summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2018-04-13 18:39:10 -0700
committerTim Graham <timograham@gmail.com>2018-04-23 13:03:07 -0400
commitd1413c5d703c60dfb9e2a418c79b3e4aed32ffac (patch)
tree59f5a13de1561e5b4930cae91aee9f163a40d076 /tests/model_forms
parent3fca95e1ad5b355f7813b98c97a194a30f2ab47b (diff)
downloaddjango-d1413c5d703c60dfb9e2a418c79b3e4aed32ffac.tar.gz
Refs #28312 -- Added an optimized __bool__() to ModelChoiceIterator.
COUNT is more expensive than EXISTS; use the latter when possible.
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/test_modelchoicefield.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 975873c7f9..adb3754382 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -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())