From d1413c5d703c60dfb9e2a418c79b3e4aed32ffac Mon Sep 17 00:00:00 2001 From: François Freitag Date: Fri, 13 Apr 2018 18:39:10 -0700 Subject: Refs #28312 -- Added an optimized __bool__() to ModelChoiceIterator. COUNT is more expensive than EXISTS; use the latter when possible. --- tests/model_forms/test_modelchoicefield.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/model_forms') 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()) -- cgit v1.3