mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #28312 -- Added an optimized __bool__() to ModelChoiceIterator.
COUNT is more expensive than EXISTS; use the latter when possible.
This commit is contained in:
committed by
Tim Graham
parent
3fca95e1ad
commit
d1413c5d70
@@ -115,6 +115,17 @@ class ModelChoiceFieldTests(TestCase):
|
||||
(c4.pk, 'Fourth'),
|
||||
])
|
||||
|
||||
def test_choices_bool(self):
|
||||
f = forms.ModelChoiceField(Category.objects.all(), empty_label=None)
|
||||
self.assertIs(bool(f.choices), True)
|
||||
Category.objects.all().delete()
|
||||
self.assertIs(bool(f.choices), False)
|
||||
|
||||
def test_choices_bool_empty_label(self):
|
||||
f = forms.ModelChoiceField(Category.objects.all(), empty_label='--------')
|
||||
Category.objects.all().delete()
|
||||
self.assertIs(bool(f.choices), True)
|
||||
|
||||
def test_deepcopies_widget(self):
|
||||
class ModelChoiceForm(forms.Form):
|
||||
category = forms.ModelChoiceField(Category.objects.all())
|
||||
|
||||
Reference in New Issue
Block a user