How can I customize field names in create/edit forms in Flask-Admin?
I know how to change the table name:
class User(db.Model):
__tablename__ = 'user'
id = db.Column('user_id', db.Integer, primary_key=True, autoincrement=True)
first_name = db.Column(db.String(100))
last_name = db.Column(db.String(100))
login = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120))
password = db.Column(db.String(128))
from flask.ext.admin.contrib.sqla import ModelView
class MyModelView(ModelView):
def is_accessible(self):
return current_user.is_authenticated()
admin = Admin(app, u'CustomName')
admin.add_view(MyModelView(User, db.session, u'Custom Table Name'))
In create/edit forms I get field name like name of columns in User db.Model.
How I can simply change this field name?
For example, to get 'Foo' instead of 'login' in create form for a User?
You are looking for column_labels
.
class MyModelView(ModelView):
column_labels = dict(last_name='CUSTOM LAST NAME')
def is_accessible(self):
return current_user.is_authenticated()
You can:
column_list = ['user.name', 'timestamp']
column_labels = {
'user.name': 'Full Name',
'timestamp' : 'Created Date'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With