Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12901. Again. Model validation will not be performed on exclud…

…ed 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
  • Loading branch information...
commit e488c1dc0d29f2de0d8bb31db604aa6384b7a60b 1 parent c736cbe
Joseph Kocherhans authored February 25, 2010
2  django/forms/models.py
@@ -280,6 +280,8 @@ def _get_validation_exclusions(self):
280 280
             # class. See #12901.
281 281
             elif self._meta.fields and field not in self._meta.fields:
282 282
                 exclude.append(f.name)
  283
+            elif self._meta.exclude and field in self._meta.exclude:
  284
+                exclude.append(f.name)
283 285
 
284 286
             # Exclude fields that failed form validation. There's no need for
285 287
             # the model fields to validate them as well.
22  tests/modeltests/model_forms/tests.py
@@ -3,7 +3,7 @@
3 3
 from models import Category
4 4
 
5 5
 
6  
-class IncompleteCategoryForm(forms.ModelForm):
  6
+class IncompleteCategoryFormWithFields(forms.ModelForm):
7 7
     """
8 8
     A form that replaces the model's url field with a custom one. This should
9 9
     prevent the model field's validation from being called.
@@ -14,8 +14,24 @@ class Meta:
14 14
         fields = ('name', 'slug')
15 15
         model = Category
16 16
 
  17
+class IncompleteCategoryFormWithExclude(forms.ModelForm):
  18
+    """
  19
+    A form that replaces the model's url field with a custom one. This should
  20
+    prevent the model field's validation from being called.
  21
+    """
  22
+    url = forms.CharField(required=False)
  23
+
  24
+    class Meta:
  25
+        exclude = ['url']
  26
+        model = Category
  27
+
  28
+
17 29
 class ValidationTest(TestCase):
18  
-    def test_validates_with_replaced_field(self):
19  
-        form = IncompleteCategoryForm(data={'name': 'some name', 'slug': 'some-slug'})
  30
+    def test_validates_with_replaced_field_not_specified(self):
  31
+        form = IncompleteCategoryFormWithFields(data={'name': 'some name', 'slug': 'some-slug'})
  32
+        assert form.is_valid()
  33
+
  34
+    def test_validates_with_replaced_field_excluded(self):
  35
+        form = IncompleteCategoryFormWithExclude(data={'name': 'some name', 'slug': 'some-slug'})
20 36
         assert form.is_valid()
21 37
 

0 notes on commit e488c1d

Please sign in to comment.
Something went wrong with that request. Please try again.