diff options
| author | Marti Raudsepp <marti@voicecom.ee> | 2015-11-05 19:02:18 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-09 12:42:36 -0500 |
| commit | 1155843a41af589a856efe8e671a796866430049 (patch) | |
| tree | 54bee0a344bb8c92cca1413428aad1ee06232ef6 /tests | |
| parent | c6da4b0c687e9a0d1661e9a310f703b30c4a0988 (diff) | |
Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.
This fixes a regression from refs #25496.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/forms_tests/tests/tests.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index b3a1cd1f1d..74005ce6fe 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -60,17 +60,23 @@ class FileForm(Form): file1 = FileField() -class TestTicket12510(TestCase): - ''' It is not necessary to generate choices for ModelChoiceField (regression test for #12510). ''' - def setUp(self): - self.groups = [Group.objects.create(name=name) for name in 'abc'] +class TestModelChoiceField(TestCase): def test_choices_not_fetched_when_not_rendering(self): + """ + Generating choices for ModelChoiceField should require 1 query (#12510). + """ + self.groups = [Group.objects.create(name=name) for name in 'abc'] # only one query is required to pull the model from DB with self.assertNumQueries(1): field = ModelChoiceField(Group.objects.order_by('-name')) self.assertEqual('a', field.clean(self.groups[0].pk).name) + def test_queryset_manager(self): + f = ModelChoiceField(ChoiceOptionModel.objects) + choice = ChoiceOptionModel.objects.create(name="choice 1") + self.assertEqual(list(f.choices), [('', '---------'), (choice.pk, str(choice))]) + class TestTicket14567(TestCase): """ |
