-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
28 lines (21 loc) · 865 Bytes
/
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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Province(db.Model):
__tablename__ = "provinces"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30), nullable=False, unique=True)
cities = db.relationship("City", backref="province", lazy=True)
def __repr__(self):
return f"Province(name={self.name})"
class City(db.Model):
__tablename__ = "cities"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30), nullable=False)
population = db.Column(db.Integer)
province_id = db.Column(db.Integer,
db.ForeignKey("provinces.id"),
nullable=False)
def __repr__(self):
return f"""<City(name={self.name},
population={self.population},
province_id={self.id})>"""