Readonly text field in Flask-Admin ModelView

前端 未结 5 1295
南旧
南旧 2020-12-18 23:23

How can I make a field on a ModelView readonly?

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


        
5条回答
  •  难免孤独
    2020-12-19 00:16

    I don't have enough reputation to comment on @thkang's answer, which is very close to what worked for me. The disabled attribute excludes the field from the POST data, but using readonly had the desired effect.

    from wtforms.fields import TextField
    
    class ReadonlyTextField(TextField):
      def __call__(self, *args, **kwargs):
        kwargs.setdefault('readonly', True)
        return super(ReadonlyTextField, self).__call__(*args, **kwargs)
    

提交回复
热议问题