Code

Ticket #8160: 8160_test.diff

File 8160_test.diff, 1.3 KB (added by claudep, 3 years ago)

Test showing working functionality

Line 
1diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
2index 34f8d47..ee58702 100644
3--- a/tests/modeltests/model_formsets/tests.py
4+++ b/tests/modeltests/model_formsets/tests.py
5@@ -353,6 +353,28 @@ class ModelFormsetTest(TestCase):
6         self.assertEqual(poet1.name, 'Vladimir Mayakovsky')
7         self.assertEqual(poet2.name, 'Vladimir Mayakovsky')
8 
9+    def test_custom_form(self):
10+        """ Test that model_formset respects fields and exclude parameters of
11+            custom form
12+        """
13+        class PostForm1(forms.ModelForm):
14+            class Meta:
15+                model = Post
16+                fields = ('title', 'posted')
17+
18+        class PostForm2(forms.ModelForm):
19+            class Meta:
20+                model = Post
21+                exclude = ('subtitle',)
22+
23+        PostFormSet = modelformset_factory(Post, form=PostForm1)
24+        formset = PostFormSet()
25+        self.assertFalse("subtitle" in formset.forms[0].fields)
26+
27+        PostFormSet = modelformset_factory(Post, form=PostForm2)
28+        formset = PostFormSet()
29+        self.assertFalse("subtitle" in formset.forms[0].fields)
30+
31     def test_model_inheritance(self):
32         BetterAuthorFormSet = modelformset_factory(BetterAuthor)
33         formset = BetterAuthorFormSet()