Custom field name in Flask-Admin

How to 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 the create / edit forms, I get the field name, for example the column name in User db.Model.

How can I just change this field name?
For example, to get "Foo" instead of "login" in the creation form for the user?

+5
source share
1 answer

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() 
+10
source

Source: https://habr.com/ru/post/1202975/


All Articles