diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2010-03-18 02:03:07 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2010-03-18 02:03:07 +0000 |
| commit | 7471dab660d916ab2ebd6b943aec6c2b1145e744 (patch) | |
| tree | 9927c4764021aa7641287caa98eda3d94165d9c2 /django/forms/models.py | |
| parent | e434573ef12934d8e8f77e2e794d2968dd734ded (diff) | |
Fixed #13138: Ensure required=False on a model form field overrides
blank=False on the underlying model field during model form clean,
in order to maintain backward compatibility. Thanks to saxon75 for
the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12802 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 13aea4acab..869138c922 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -292,13 +292,16 @@ class BaseModelForm(BaseForm): elif field in self._errors.keys(): exclude.append(f.name) - # Exclude empty fields that are not required by the form. The - # underlying model field may be required, so this keeps the model - # field from raising that error. + # Exclude empty fields that are not required by the form, if the + # underlying model field is required. This keeps the model field + # from raising a required error. Note: don't exclude the field from + # validaton if the model field allows blanks. If it does, the blank + # value may be included in a unique check, so cannot be excluded + # from validation. else: form_field = self.fields[field] field_value = self.cleaned_data.get(field, None) - if field_value is None and not form_field.required: + if not f.blank and not form_field.required and field_value in EMPTY_VALUES: exclude.append(f.name) return exclude |
