-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmodels.py
154 lines (121 loc) · 4.68 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Models and fixtures taked from Swapi
# Swapi URL project: https://github.com/phalt/swapi/
# https://github.com/phalt/swapi/blob/master/resources/models.py
from __future__ import unicode_literals
from django.db import models
class DateTimeModel(models.Model):
""" A base model with created and edited datetime fields """
created = models.DateTimeField(auto_now_add=True)
edited = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class Planet(DateTimeModel):
""" A planet i.e. Tatooine """
name = models.CharField(max_length=100)
rotation_period = models.CharField(max_length=40)
orbital_period = models.CharField(max_length=40)
diameter = models.CharField(max_length=40)
climate = models.CharField(max_length=40)
gravity = models.CharField(max_length=40)
terrain = models.CharField(max_length=40)
surface_water = models.CharField(max_length=40)
population = models.CharField(max_length=40)
def __unicode__(self):
return self.name
class People(DateTimeModel):
""" A person i.e. - Luke Skywalker """
name = models.CharField(max_length=100)
height = models.CharField(max_length=10, blank=True)
mass = models.CharField(max_length=10, blank=True)
hair_color = models.CharField(max_length=20, blank=True)
skin_color = models.CharField(max_length=20, blank=True)
eye_color = models.CharField(max_length=20, blank=True)
birth_year = models.CharField(max_length=10, blank=True)
gender = models.CharField(max_length=40, blank=True)
homeworld = models.ForeignKey(Planet, related_name="residents", on_delete=models.CASCADE)
def __unicode__(self):
return self.name
class Transport(DateTimeModel):
name = models.CharField(max_length=40)
model = models.CharField(max_length=40)
manufacturer = models.CharField(max_length=80)
cost_in_credits = models.CharField(max_length=40)
length = models.CharField(max_length=40)
max_atmosphering_speed = models.CharField(max_length=40)
crew = models.CharField(max_length=40)
passengers = models.CharField(max_length=40)
cargo_capacity = models.CharField(max_length=40)
consumables = models.CharField(max_length=40)
def __unicode__(self):
return self.name
class Starship(Transport):
""" A starship is a transport with a hypderdrive """
hyperdrive_rating = models.CharField(max_length=40)
MGLT = models.CharField(max_length=40)
starship_class = models.CharField(max_length=40)
pilots = models.ManyToManyField(
People,
related_name="starships",
blank=True
)
class Vehicle(Transport):
""" A vehicle is anything without hyperdrive capability """
vehicle_class = models.CharField(max_length=40)
pilots = models.ManyToManyField(
People,
related_name="vehicles",
blank=True
)
class Species(DateTimeModel):
"A species is a type of alien or person"
name = models.CharField(max_length=40)
classification = models.CharField(max_length=40)
designation = models.CharField(max_length=40)
average_height = models.CharField(max_length=40)
skin_colors = models.CharField(max_length=200)
hair_colors = models.CharField(max_length=200)
eye_colors = models.CharField(max_length=200)
average_lifespan = models.CharField(max_length=40)
homeworld = models.ForeignKey(Planet, blank=True, null=True, on_delete=models.CASCADE)
language = models.CharField(max_length=40)
people = models.ManyToManyField(People, related_name="species")
def __unicode__(self):
return self.name
class Film(DateTimeModel):
""" A film i.e. The Empire Strikes Back (which is also the best film) """
title = models.CharField(max_length=100)
episode_id = models.IntegerField()
opening_crawl = models.TextField(max_length=1000)
director = models.CharField(max_length=100)
producer = models.CharField(max_length=100)
release_date = models.DateField()
characters = models.ManyToManyField(
People,
related_name="films",
blank=True
)
planets = models.ManyToManyField(
Planet,
related_name="films",
blank=True
)
starships = models.ManyToManyField(
Starship,
related_name="films",
blank=True
)
vehicles = models.ManyToManyField(
Vehicle,
related_name="films",
blank=True
)
species = models.ManyToManyField(
Species,
related_name="films",
blank=True
)
def __unicode__(self):
return self.title
class Hero(DateTimeModel):
name = models.CharField(max_length=100)
homeworld = models.ForeignKey(Planet, related_name="heroes", on_delete=models.CASCADE)