Code

Ticket #15282: testcase.diff

File testcase.diff, 1.6 KB (added by coleifer, 3 years ago)

testcase indicating failure

Line 
1diff --git a/tests/regressiontests/inline_formsets/forms.py b/tests/regressiontests/inline_formsets/forms.py
2new file mode 100644
3index 0000000..e7d752f
4--- /dev/null
5+++ b/tests/regressiontests/inline_formsets/forms.py
6@@ -0,0 +1,8 @@
7+from django import forms
8+
9+from regressiontests.inline_formsets.models import Poem
10+
11+
12+class PoemModelForm(forms.ModelForm):
13+    class Meta:
14+        model = Poem
15diff --git a/tests/regressiontests/inline_formsets/tests.py b/tests/regressiontests/inline_formsets/tests.py
16index 5bd9d18..76d087b 100644
17--- a/tests/regressiontests/inline_formsets/tests.py
18+++ b/tests/regressiontests/inline_formsets/tests.py
19@@ -1,6 +1,7 @@
20 from django.forms.models import inlineformset_factory
21 from django.test import TestCase
22 
23+from regressiontests.inline_formsets.forms import PoemModelForm
24 from regressiontests.inline_formsets.models import Poet, Poem, School, Parent, Child
25 
26 
27@@ -154,3 +155,21 @@ class InlineFormsetFactoryTest(TestCase):
28         inlineformset_factory(
29             Parent, Child, exclude=('school',), fk_name='mother'
30         )
31+
32+
33+class FormOverrideTestCase(TestCase):
34+    def test_overrides_intact(self):
35+        emily = Poet.objects.create(name='Emily Dickinson')
36+        edgar = Poet.objects.create(name='Edgar Allan Poe')
37+       
38+        # override the queryset
39+        PoemModelForm.base_fields['poet'].queryset = Poet.objects.filter(
40+            name='Emily Dickinson'
41+        )
42+       
43+        # send our form in
44+        formset = inlineformset_factory(
45+            Poet, Poem, form=PoemModelForm, extra=1
46+        )
47+       
48+        self.assertEqual(list(formset.form.base_fields['poet'].queryset), [emily])