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:44:34 -0500 |
| commit | 8db5122d6937bfcaf9a5894ba8f329d2a4424ca5 (patch) | |
| tree | 058ab8897ee68f1ce8b87fb17645299ded4fee9f /tests | |
| parent | 6858bf758ccf1cd6ce46f3fc0b547f52cd7339db (diff) | |
[1.9.x] Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.
This fixes a regression from refs #25496.
Backport of 1155843a41af589a856efe8e671a796866430049 from master
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 a633b2da8a..6a0d8aaebe 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): """ |
