summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2014-07-25 19:20:00 +0200
committerFlorian Apolloner <florian@apolloner.eu>2014-07-27 13:31:25 +0200
commit2f73b527dda6683868fac2791f7f07ccb01ea0d9 (patch)
tree45588c0291a73bc6197956c06026c76116e1d630 /django
parent2ab0ed7b2842fbb8bf36ee7df9949d10546d953d (diff)
Fixed #23098 -- Checked that lazy choices are not evaluated too soon
Thanks Matthieu Agopian for the report.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/__init__.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 56c25f0045..99bb948184 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -730,10 +730,12 @@ class Field(RegisterLookupMixin):
"""Returns choices with a default blank choices included, for use
as SelectField choices for this field."""
blank_defined = False
- for choice, __ in self.choices:
- if choice in ('', None):
- blank_defined = True
- break
+ named_groups = self.choices and isinstance(self.choices[0][1], (list, tuple))
+ if not named_groups:
+ for choice, __ in self.choices:
+ if choice in ('', None):
+ blank_defined = True
+ break
first_choice = (blank_choice if include_blank and
not blank_defined else [])