summaryrefslogtreecommitdiff
path: root/tests/model_forms/test_modelchoicefield.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_forms/test_modelchoicefield.py')
-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 40c625da7c..f2f75829d1 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -169,6 +169,17 @@ class ModelChoiceFieldTests(TestCase):
Category.objects.all().delete()
self.assertIs(bool(f.choices), False)
+ def test_empty_label_one_query(self):
+ class MyForm(forms.Form):
+ f = forms.ModelChoiceField(Category.objects.all(), empty_label=None)
+
+ form = MyForm()
+ with self.assertNumQueries(1):
+ form.as_ul()
+ # Make sure the query re-runs when re-rendering the form.
+ with self.assertNumQueries(1):
+ form.as_ul()
+
def test_choices_bool_empty_label(self):
f = forms.ModelChoiceField(Category.objects.all(), empty_label="--------")
Category.objects.all().delete()