File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
tests/modeltests/model_forms Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -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.
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments