问题
I am facing to performance problem in Flask-Admin, although performance of Flask application is good.
my model is:
class Ck(Base):
__tablename__ = "ck"
id = Column(Integer, primary_key=True, autoincrement=True)
nazev = Column(String(100))
kontakt = Column(Text)
terms = relationship(Term, backref=backref('ck', lazy='noload'), lazy='dynamic')
class Term(Base):
__tablename__ = "term"
id = Column(Integer, primary_key=True, autoincrement=True)
hotel_id = Column(Integer, ForeignKey('hotel.id'))
ck_id = Column(Integer, ForeignKey('ck.id'))
...
addons = relationship(Addon, secondary=term_addon, backref=backref('term', lazy='noload'), lazy='dynamic')
class Hotel(Base):
__tablename__ = "hotel"
id = Column(Integer, primary_key=True, autoincrement=True)
country_id = Column(Integer, ForeignKey('country.id'))
area_id = Column(Integer, ForeignKey('area.id'))
...
photos = relationship(Photo, backref=backref('hotel', lazy='select'), lazy='dynamic')
terms = relationship(Term, backref=backref('hotel', lazy='noload'), lazy='dynamic')
class Addon(Base):
__tablename__ = "addon"
id = Column(Integer, primary_key=True, autoincrement=True)
...
There are really lot of records in terms and much more in addons. If I click to anywhere to get details of Hotel, Term, Ck or Addon in Flask-Admin, it is not possible, because it doesn't finish till timeout.
Please could you advise me where I can improve it? Thank you
回答1:
Enable AJAX foreign key loading. See here: http://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask.ext.admin.model.BaseModelView.form_ajax_refs
来源:https://stackoverflow.com/questions/22894861/flask-admin-performance-difficulties