-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
116 lines (100 loc) · 3.89 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
from flask_sqlalchemy import SQLAlchemy
import datetime
db = SQLAlchemy()
class User(db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(200), nullable=False, unique=True)
first_name = db.Column(db.String(200), nullable=False)
last_name = db.Column(db.String(200), nullable=False)
favorite_character = db.relationship("Favorite_character")
favorite_planet = db.relationship("Favorite_planet")
def serialize(self):
return {
"id": self.id,
"email": self.email,
"first_name": self.first_name,
"last_name": self.last_name,
}
class Favorite_character(db.Model):
__tablename__ = "favorite_character"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
type = db.Column(db.String(200), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.datetime.now())
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
character_id = db.Column(db.Integer, db.ForeignKey("character.id"))
def serialize(self):
return {
"id": self.id,
"name": self.name,
"type": self.type,
"created_at": self.created_at,
"user_id": self.user_id,
"character_id": self.character_id,
}
class Character(db.Model):
__tablename__ = "character"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
description = db.Column(db.String(200))
gender = db.Column(db.String(200), nullable=False)
hair_color = db.Column(db.String(200))
eye_color = db.Column(db.String(200))
favorite_character = db.relationship("Favorite_character")
def serialize(self):
return {
"id": self.id,
"name": self.name,
"description": self.description,
"gender": self.gender,
"hair_color": self.hair_color,
"eye_color": self.eye_color,
}
class Favorite_planet(db.Model):
__tablename__ = "favorite_planet"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
type = db.Column(db.String(200), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.datetime.now())
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
planet_id = db.Column(db.Integer, db.ForeignKey("planet.id"))
def serialize(self):
return {
"id": self.id,
"name": self.name,
"type": self.type,
"created_at": self.created_at,
"user_id": self.user_id,
"planet_id": self.planet_id,
}
class Planet(db.Model):
__tablename__ = "planet"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
description = db.Column(db.String(200))
lenght = db.Column(db.Integer, nullable=False)
diameter = db.Column(db.Integer, nullable=False)
rotation_period = db.Column(db.String(200))
orbital_period = db.Column(db.String(200))
gravity = db.Column(db.String(200))
population = db.Column(db.Integer, nullable=False)
climate = db.Column(db.String(200))
terrain = db.Column(db.String(200))
surface_water = db.Column(db.String(200))
favorite_planet = db.relationship("Favorite_planet")
def serialize(self):
return {
"id": self.id,
"name": self.name,
"description": self.description,
"lenght": self.lenght,
"diameter": self.diameter,
"rotation_period": self.rotation_period,
"orbital_period": self.orbital_period,
"gravity": self.gravity,
"population": self.population,
"climate": self.climate,
"terrain": self.terrain,
"surface_water": self.surface_water,
}