Validation should allow excluded fields
|Reported by:||Berislav Lopac||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As of 1.2 alpha 1, the ModelForm validation throws an UnresolvableValidationError in the situation where a required field is excluded in the Meta subclass. I understand the intent behind that, but I believe this is broken; luckily, there is a simple way to implement it a bit differently.
Form is not the same as the Model, and ModelForm is nothing but a shortcut to create a form that follows a Model's fields. If a field is hidden from a Form, it should not evaluate it, and the Model will take care of itself: if the field in question has null=False, the Model's save() method will throw an exception anyway.
Luckily, there is already a mechanism which can help us here: blank=True is used in admin to allow a value, so I think that it should be used with regular ModelForms as well. Currently, the only way to pass the validation is that the Model field has both blank=True and null=True, but this is not what we need here: we need a mechanism to separate form validation from the model.
So I propose that only the blank attribute is validated in the ModelForm for excluded fields: if blank=True a None value is allowed for excluded fields, otherwise a UnresolvableValidationError is thrown.