I like to change the name display at the top level menu of Flask-Admin. By default it seems he uses the calass model name. I like to change that for a more Human readable Name.
I've seen that in the "layout.htlm" template, there is a variable called {{ item.name }}
. This is used to display the name of the menu. Is there a way to change that for another name or to surcharge the name in the model definition ?
Using __tablename__
doesn't work and will break internal flask-admin. Is there an equivalent to __repr__
but for table name instead of column.
Regards
BaseModelView
accepts an argument named name
. If you provide a value, it will be used for display on the menu.
from flask.ext.admin.model import BaseModelView
admin.add_view(BaseModelView(MyModel, 'Menu Text'))
If you are using SQLAlchemy:
from flask.ext.admin.contrib.sqla import ModelView
admin.add_view(ModelView(MyModel, db.session, 'Menu Text'))
Here I've used positional arguments, but I could have just as easily done name='Menu Text'
instead.