Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide fields from ModelView in Flask-admin form_create

Tags:

flask-admin

Is there a proper way of excluding fields from showing up in the create form of Flask-admin? I would normally do something like this in order to specify which fields to show on the create and edit form:

class UserView(sqla.ModelView):
    form_create_rules = { 'username' }
    form_edit_rules = ('username', 'photos')

Even though this works as expected, I get the following warning when running my application:

UserWarning: Fields missing from ruleset: photos
  warnings.warn(text)

Is there a better way of defining what fields to show on each form that doesn't give me that error?

like image 501
NeoID Avatar asked Apr 23 '26 18:04

NeoID


1 Answers

If I understand correctly, you can use properties of the ModelView class:

form_columns - Collection of the model field names for the form. If set to None will get them from the model.

or

form_excluded_columns - Collection of the model field names for the form. If set to None will get them from the model.

You can find more info inside Flask-Admin Docs.

I also should mention that this will work for both Create and Edit forms.

like image 138
tm- Avatar answered Apr 30 '26 02:04

tm-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!