python - Flask-Admin: add filters on foreign keys -
i using flask-admin create back-end interface application. want add filters in admin view, error
'exception: unsupported filter type column_name'
where column name column field foreign key. has worked flask-admin before?
here models:
class keywords(base): id = column(string(4), primary_key=true) language = column(foreignkey('w_accounts.language')) camp_type = column(foreignkey('w_camp_types.camp_type')) class keywordsadmin(baseadmin): column_searchable_list = ('toa_id', 'name', 'toa') column_list = ('toa_id', 'language', 'camp_type', 'name', 'aliases', 'toa', 'toa_type') column_filters = ('language',)
after going through api, tried add following attribute well:
column_select_related_list = ('language',)
instead of getting error exception when load page on browser,
"attributeerror: 'columnproperty' object has no attribute 'mapper'"
you have add relationship.
class keywords(base): id = column(string(4), primary_key=true) language = column(foreignkey('w_accounts.language')) camp_type = column(foreignkey('w_camp_types.camp_type')) language_ref = relationship("w_accounts", backref=db.backref('keywords', lazy='dynamic'))
and then:
column_select_related_list = ('language_ref',)
Comments
Post a Comment