diff options
| author | Charles Roelli <charles@aurox.ch> | 2026-05-05 09:24:59 +0000 |
|---|---|---|
| committer | Charles Roelli <charles@aurox.ch> | 2026-05-05 09:24:59 +0000 |
| commit | b3c1fd51b6537c122b8ead6aa9234685560866d8 (patch) | |
| tree | 544c306118205eb54bbd1ab97d3ea5e863dfc913 /django/forms/widgets.py | |
| parent | 9f790ef1a0f356cf6342b5d57bbaeac35aed0d9f (diff) | |
Fixed #31295 -- Avoided Select widget triggering additional query when using ModelChoiceIterator.fix-31295
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 6 |
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 |
