Author: jkocherhans
Date: 2010-02-25 11:18:27 -0600 (Thu, 25 Feb 2010)
New Revision: 12590
Modified:
django/trunk/django/forms/models.py
django/trunk/tests/modeltests/model_forms/tests.py
Log:
Fixed #12901. Again. Model validation will not be performed on excluded fields
that were overridden in the form. Thanks, ammarr.
Modified: django/trunk/django/forms/models.py
===================================================================
--- django/trunk/django/forms/models.py 2010-02-25 17:14:37 UTC (rev 12589)
+++ django/trunk/django/forms/models.py 2010-02-25 17:18:27 UTC (rev 12590)
@@ -280,6 +280,8 @@
# class. See #12901.
elif self._meta.fields and field not in self._meta.fields:
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
# the model fields to validate them as well.
Modified: django/trunk/tests/modeltests/model_forms/tests.py
===================================================================
--- django/trunk/tests/modeltests/model_forms/tests.py 2010-02-25 17:14:37 UTC
(rev 12589)
+++ django/trunk/tests/modeltests/model_forms/tests.py 2010-02-25 17:18:27 UTC
(rev 12590)
@@ -3,7 +3,7 @@
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
prevent the model field's validation from being called.
@@ -14,8 +14,24 @@
fields = ('name', 'slug')
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):
- def test_validates_with_replaced_field(self):
- form = IncompleteCategoryForm(data={'name': 'some name', 'slug':
'some-slug'})
+ def test_validates_with_replaced_field_not_specified(self):
+ 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()
+
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.