选项参数可以是调用所以这样做以下(使用你链接到为例):
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