我已经阅读了其他答案,但似乎没有一个回答这个问题,我克隆了sandman2,它在管理仪表板中没有列过滤器和列搜索选项,下面是ModelView
from flask_admin.contrib.sqla import ModelView
class CustomAdminView(ModelView): # pylint: disable=no-init
"""Define custom templates for each view."""
list_template = 'list.html'
create_template = 'create.html'
edit_template = 'edit.html'
column_display_pk = True
ModelView.can_export = True
ModelView.can_delete = False
ModelView.can_view_details = True
ModelView.can_set_page_size = True
ModelView.can_create = False
ModelView.page_size = 500
我把这个叫做app.py
def register_model(cls, admin=None):
"""Register *cls* to be included in the API service
:param cls: Class deriving from :class:`sandman2.models.Model`
"""
cls.__url__ = '/{}'.format(cls.__name__.lower())
service_class = type(
cls.__name__ + 'Service',
(Service,),
{
'__model__': cls,
})
# inspect primary key
cols = list(cls().__table__.primary_key.columns)
# composite keys not supported (yet)
primary_key_type = 'string'
if len(cols) == 1:
col_type = cols[0].type
# types defined at http://flask.pocoo.org/docs/0.10/api/#url-route-registrations
if isinstance(col_type, sqltypes.String):
primary_key_type = 'string'
elif isinstance(col_type, sqltypes.Integer):
primary_key_type = 'int'
elif isinstance(col_type, sqltypes.Numeric):
primary_key_type = 'float'
# registration
register_service(service_class, primary_key_type)
if admin is not None:
columns = (c.name for c in (list(cls().__table__.columns)) if not c.primary_key)
cv = CustomAdminView(cls, db.session)
cv.column_filters = columns
cv.column_searchable_list = list(columns)
admin.add_view(cv)
仍然没有运气,管理员上没有筛选选项,也没有筛选选项
目前没有回答
相关问题 更多 >
编程相关推荐