summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorJames Beith <james@beith.co.uk>2017-03-22 16:38:16 +1100
committerTim Graham <timograham@gmail.com>2017-03-22 08:57:02 -0400
commit6963564ecc1b84cb2510616123a27d368bc76a1f (patch)
treea5845dc130f5fce785b0533faf521b94a53d405c /tests/model_forms
parentda72d0730eb0ff335404c13925afc962ac565c79 (diff)
[1.11.x] Fixed #27975 -- Fixed crash if ModelChoiceField's queryset=None.
Regression in 9153d8fbd6385db9f48793662de789fc3d686841. Backport of 216bb2e8fbc3cb37615bbd70edaa73287acdca81 from master
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/tests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 2ff4435385..c8d22db6e8 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -1646,6 +1646,17 @@ class ModelChoiceFieldTests(TestCase):
form2 = ModelChoiceForm()
self.assertIsNone(form2.fields['category'].queryset._result_cache)
+ def test_modelchoicefield_queryset_none(self):
+ class ModelChoiceForm(forms.Form):
+ category = forms.ModelChoiceField(queryset=None)
+
+ def __init__(self, *args, **kwargs):
+ super(ModelChoiceForm, self).__init__(*args, **kwargs)
+ self.fields['category'].queryset = Category.objects.filter(slug__contains='test')
+
+ form = ModelChoiceForm()
+ self.assertCountEqual(form.fields['category'].queryset, [self.c2, self.c3])
+
def test_modelchoicefield_22745(self):
"""
#22745 -- Make sure that ModelChoiceField with RadioSelect widget