summaryrefslogtreecommitdiff
path: root/tests/model_forms/test_modelchoicefield.py
diff options
context:
space:
mode:
authorCharles Roelli <charles@aurox.ch>2026-05-01 13:45:01 +0000
committerCharles Roelli <charles@aurox.ch>2026-05-01 13:45:01 +0000
commit70b0be281caa08a0b639acb73e3b9fe5f6e7d278 (patch)
tree52f99149db13ccf9af6ad6d91d06110725b7224a /tests/model_forms/test_modelchoicefield.py
parent9f790ef1a0f356cf6342b5d57bbaeac35aed0d9f (diff)
Fixed #31295 -- Avoid Select widget triggering additional query when using ModelChoiceIterator.fix-31295
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()