Fixed #12901. Again. Model validation will not be performed on excluded fields that were overridden in the form. Thanks, ammarr.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12590 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c736cbe816
commit
e488c1dc0d
|
@ -280,6 +280,8 @@ class BaseModelForm(BaseForm):
|
||||||
# class. See #12901.
|
# class. See #12901.
|
||||||
elif self._meta.fields and field not in self._meta.fields:
|
elif self._meta.fields and field not in self._meta.fields:
|
||||||
exclude.append(f.name)
|
exclude.append(f.name)
|
||||||
|
elif self._meta.exclude and field in self._meta.exclude:
|
||||||
|
exclude.append(f.name)
|
||||||
|
|
||||||
# Exclude fields that failed form validation. There's no need for
|
# Exclude fields that failed form validation. There's no need for
|
||||||
# the model fields to validate them as well.
|
# the model fields to validate them as well.
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django import forms
|
||||||
from models import Category
|
from models import Category
|
||||||
|
|
||||||
|
|
||||||
class IncompleteCategoryForm(forms.ModelForm):
|
class IncompleteCategoryFormWithFields(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
A form that replaces the model's url field with a custom one. This should
|
A form that replaces the model's url field with a custom one. This should
|
||||||
prevent the model field's validation from being called.
|
prevent the model field's validation from being called.
|
||||||
|
@ -14,8 +14,24 @@ class IncompleteCategoryForm(forms.ModelForm):
|
||||||
fields = ('name', 'slug')
|
fields = ('name', 'slug')
|
||||||
model = Category
|
model = Category
|
||||||
|
|
||||||
|
class IncompleteCategoryFormWithExclude(forms.ModelForm):
|
||||||
|
"""
|
||||||
|
A form that replaces the model's url field with a custom one. This should
|
||||||
|
prevent the model field's validation from being called.
|
||||||
|
"""
|
||||||
|
url = forms.CharField(required=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
exclude = ['url']
|
||||||
|
model = Category
|
||||||
|
|
||||||
|
|
||||||
class ValidationTest(TestCase):
|
class ValidationTest(TestCase):
|
||||||
def test_validates_with_replaced_field(self):
|
def test_validates_with_replaced_field_not_specified(self):
|
||||||
form = IncompleteCategoryForm(data={'name': 'some name', 'slug': 'some-slug'})
|
form = IncompleteCategoryFormWithFields(data={'name': 'some name', 'slug': 'some-slug'})
|
||||||
|
assert form.is_valid()
|
||||||
|
|
||||||
|
def test_validates_with_replaced_field_excluded(self):
|
||||||
|
form = IncompleteCategoryFormWithExclude(data={'name': 'some name', 'slug': 'some-slug'})
|
||||||
assert form.is_valid()
|
assert form.is_valid()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue