NeoID
NeoID

Reputation: 901

Hide fields from ModelView in Flask-admin form_create

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?

Upvotes: 3

Views: 5568

Answers (1)

tm-
tm-

Reputation: 353

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.

Upvotes: 9

Related Questions