選項參數可以是調用所以這樣做以下(使用你鏈接到爲例):
def get_all_last_names():
unique_last_names = User.query.with_entities(User.last_name.distinct().label("last_name")).order_by(User.last_name.asc()).all()
return [(user.last_name, user.last_name) for user in unique_last_names]
class UserAdmin(sqla.ModelView):
column_filters = [
FilterEqual(column=User.last_name, name='Last Name', options=get_all_last_names),
]
# This is probably NOT the correct way to refresh the filters cache
@expose('/')
def index_view(self):
self._refresh_filters_cache()
return super(UserAdmin, self).index_view()
Mmmh,當應用程序啓動此功能被調用。即使頁面重新載入也不會觸發它重新加載:-( – Sebi
@Sebi - 您需要更新過濾器緩存 - 我已更新我的答案 – pjcunningham