How to make a field non-editable in Flask Admin view of a model class

前端 未结 3 754
离开以前
离开以前 2021-02-20 13:03

I have a User model class and password is one attribute among many. I am using Flask web framework and Flask-Admin extension to create the admin view o

3条回答
  •  既然无缘
    2021-02-20 13:41

    You should extend your view from ModelView and overwrite the necessary fields.

    In my class it looks like this:

    class UserView(ModelView):
    
        column_list = ('first_name', 'last_name', 'username', 'email')
        searchable_columns = ('username', 'email')
    # this is to exclude the password field from list_view:
        excluded_list_columns = ['password']
        can_create = True
        can_delete = False
    # If you want to make them not editable in form view: use this piece:
        form_widget_args = {
            'name': {
                'readonly': True
            },
        }
    

    Hope this helps! For more information check out the documentation:

    • Flask-Admin Documentation
    • Model View Documentation

提交回复
热议问题