summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-07-27 07:22:39 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-07-27 07:22:39 +0000
commit661f62be3c5f810fddd3b33bcbdfe33a3077a66d (patch)
tree427d6dcabcaf5a39bb185980768973310d7ab4fd /django
parent0e629b01c0470d46be367ff394bbe345d53a9883 (diff)
Fixed #7913 -- Corrected backwards incompatible parts of [7977] when optgroup handling was added to field choices (Ticket #4412). Thanks to Michael Elsdorfer (miracle2k) for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8102 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/__init__.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 439633c45f..dd5117fb78 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -288,7 +288,7 @@ class Field(object):
if self.choices:
field_objs = [oldforms.SelectField]
- params['choices'] = self.flatchoices
+ params['choices'] = self.get_flatchoices()
else:
field_objs = self.get_manipulator_field_objs()
return (field_objs, params)
@@ -362,7 +362,8 @@ class Field(object):
return val
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
- "Returns a list of tuples used as SelectField choices for this field."
+ """Returns choices with a default blank choices included, for use
+ as SelectField choices for this field."""
first_choice = include_blank and blank_choice or []
if self.choices:
return first_choice + list(self.choices)
@@ -376,6 +377,11 @@ class Field(object):
def get_choices_default(self):
return self.get_choices()
+ def get_flatchoices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
+ "Returns flattened choices with a default blank choice included."
+ first_choice = include_blank and blank_choice or []
+ return first_choices + list(self.flatchoices)
+
def _get_val_from_obj(self, obj):
if obj:
return getattr(obj, self.attname)
@@ -408,15 +414,16 @@ class Field(object):
choices = property(_get_choices)
def _get_flatchoices(self):
+ """Flattened version of choices tuple."""
flat = []
- for choice, value in self.get_choices_default():
+ for choice, value in self.choices:
if type(value) in (list, tuple):
flat.extend(value)
else:
flat.append((choice,value))
return flat
flatchoices = property(_get_flatchoices)
-
+
def save_form_data(self, instance, data):
setattr(instance, self.name, data)