politikorama/app/model/representative.py

38 lines
1.3 KiB
Python
Raw Normal View History

2021-07-23 17:35:29 +02:00
# encoding: utf-8
from app import admin, db
from app.model.model import Model, View
class RepresentativeModel(db.Model, Model):
__tablename__ = "representative"
id = db.Column(db.Integer, primary_key=True)
2022-05-31 07:11:49 +02:00
first_name = db.Column(db.String(200))
last_name = db.Column(db.String(200))
birth_date = db.Column(db.Date)
birth_place = db.Column(db.String(200))
birth_region = db.Column(db.String(200))
birth_country_id = db.Column(db.Integer, db.ForeignKey("country.id"))
birth_country = db.relationship(
"CountryModel", foreign_keys="RepresentativeModel.birth_country_id"
)
job = db.Column(db.String(200))
2021-07-23 17:35:29 +02:00
nationality_id = db.Column(db.Integer, db.ForeignKey("country.id"))
nationality = db.relationship(
2022-05-31 07:11:49 +02:00
"CountryModel", foreign_keys="RepresentativeModel.nationality_id"
2021-07-23 17:35:29 +02:00
)
2022-05-31 07:11:49 +02:00
picture = db.Column(db.String(200))
2021-07-23 17:35:29 +02:00
def __repr__(self):
2022-05-31 07:11:49 +02:00
return f"{self.last_name.upper()} {self.first_name.capitalize()}"
2021-07-23 17:35:29 +02:00
class AdminView(View):
2022-05-31 07:11:49 +02:00
column_default_sort = "last_name"
column_exclude_list = [
"birth_region", "birth_country", "picture",
]
column_filters = ["last_name", "first_name", "nationality.name", ]
2021-07-23 17:35:29 +02:00
admin.add_view(AdminView(RepresentativeModel, db.session, name="Representative", category="CRUD"))