Readonly text field in Flask-Admin ModelView

user2071987 picture user2071987 · Feb 14, 2013 · Viewed 9.9k times · Source

How can I make a field on a ModelView readonly?

class MyModelView(BaseModelView):
    column_list = ('name', 'last_name', 'email')

Answer

Richard Aplin picture Richard Aplin · Sep 17, 2013

If you're talking about Flask-Admin with SQLAlchemy Models, and you're declaring a view by inheriting from sqlamodel.ModelView, you can just add this to your class definition:

class MyModelView(BaseModelView):
    column_list = ('name', 'last_name', 'email')
    form_widget_args = {
        'email':{
            'disabled':True
        }
    }