summaryrefslogtreecommitdiff
path: root/django/forms/widgets.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 /django/forms/widgets.py
parent9f790ef1a0f356cf6342b5d57bbaeac35aed0d9f (diff)
Fixed #31295 -- Avoid Select widget triggering additional query when using ModelChoiceIterator.fix-31295
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 1bcfeba288..82685a3fea 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -851,7 +851,11 @@ class Select(ChoiceWidget):
if self.allow_multiple_selected:
return use_required_attribute
- first_choice = next(iter(self.choices), None)
+ first_choice = (
+ self.choices.peek()
+ if hasattr(self.choices, "peek")
+ else next(iter(self.choices), None)
+ )
return (
use_required_attribute
and first_choice is not None