2021-07-23 17:35:29 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
from app import admin, db
|
|
|
|
from app.model.model import Model, View
|
|
|
|
|
2022-08-04 07:24:47 +02:00
|
|
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
|
|
|
2021-07-23 17:35:29 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-08-04 07:24:47 +02:00
|
|
|
@hybrid_property
|
|
|
|
def full_name(self):
|
|
|
|
return self.first_name + " " + self.last_name
|
|
|
|
|
2021-07-23 17:35:29 +02:00
|
|
|
def __repr__(self):
|
2022-08-04 07:24:47 +02:00
|
|
|
return f"{self.first_name.capitalize()} {self.last_name.upper()}"
|
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"))
|