summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorMarti Raudsepp <marti@voicecom.ee>2015-11-05 19:02:18 +0200
committerTim Graham <timograham@gmail.com>2015-11-09 12:47:08 -0500
commit3144785ebf9fdc19639ef3d35267283f5c2f321a (patch)
tree7939b9faf0d1b46e110a28d9016bdba3122cbd99 /tests/forms_tests
parenta42c5376e764712d8ff4a1f9dd3c2d5537722288 (diff)
[1.8.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/forms_tests')
-rw-r--r--tests/forms_tests/tests/tests.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py
index 6dafee1fb8..445f229e4a 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):
"""