The following valid code leads to warnings being printed about missing fields. In my opinion this shouldn't lead to a warning. Is there a way to disable this?
``` python,
class MyModelView(ModelView):
form_columns = ('editonly_field', 'createonly_field', 'id')
form_edit_rules = ('editonly_field', 'id')
form_create_rules = ('createonly_field', 'id')
flask-admin/flask_admin/model/base.py:1324:
UserWarning: Fields missing from ruleset: createonly_field
```
Yes, this is correct behavior.
You defined form with 3 fields, but your display rules omit one of the fields. The browser won't send the field value, wtforms will decide that it is some default value (most likely None) and it'll overwrite whatever you had in the model before.
If you want to show different fields based on the view - override appropriate form methods and contribute fields in the runtime.
I would say that proper way to fix it would be to split form_columns into form_create_columns and form_edit_columns instead. form_*_rules only affect how form is displayed, but don't affect the form itself.
What is the cleanest way to introduce the concept of form_create_columns / form_edit_columns ?
Is there a way to display the field as a hidden form element, so the proper value is retained? That would fit the model of only controlling how it is displayed, not whether it is displayed, but get the intended job done, of not allowing changes. (Yes, it trusts the client, but this kind of decision, at least in my case, is about streamlining the UI, not security.)
Most helpful comment
Yes, this is correct behavior.
You defined form with 3 fields, but your display rules omit one of the fields. The browser won't send the field value, wtforms will decide that it is some default value (most likely None) and it'll overwrite whatever you had in the model before.
If you want to show different fields based on the view - override appropriate form methods and contribute fields in the runtime.
I would say that proper way to fix it would be to split
form_columnsintoform_create_columnsandform_edit_columnsinstead.form_*_rulesonly affect how form is displayed, but don't affect the form itself.