35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
# encoding: utf-8
|
|
|
|
from app import admin, db
|
|
from app.model.model import Model, View
|
|
|
|
|
|
class ContactModel(db.Model, Model):
|
|
__tablename__ = "contact"
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
representative_id = db.Column(db.Integer, db.ForeignKey("representative.id"))
|
|
representative = db.relationship(
|
|
"RepresentativeModel", backref=db.backref("contacts", lazy="dynamic")
|
|
)
|
|
address_id = db.Column(db.Integer, db.ForeignKey("address.id"))
|
|
address = db.relationship(
|
|
"AddressModel", backref=db.backref("contacts", lazy="dynamic")
|
|
)
|
|
name = db.Column(db.String(200))
|
|
slug = db.Column(db.String(200))
|
|
value = db.Column(db.String(2000))
|
|
|
|
def __repr__(self):
|
|
return self.name
|
|
|
|
|
|
class AdminView(View):
|
|
column_default_sort = "name"
|
|
column_filters = ["representative.name", "name"]
|
|
|
|
def on_model_change(self, form, model, is_created):
|
|
model.slug = slugify(model.name)
|
|
|
|
|
|
admin.add_view(AdminView(ContactModel, db.session, name="Contact", category="CRUD"))
|