1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #4412 -- Added support for optgroups, both in the model when defining choices, and in the form field and widgets when the optgroups are displayed. Thanks to Matt McClanahan <cardinal@dodds.net>, Tai Lee <real.human@mrmachine.net> and SmileyChris for their contributions at various stages in the life of this ticket.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7977 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2008-07-19 07:53:02 +00:00
parent b5b0febc4c
commit 649463dd34
8 changed files with 204 additions and 40 deletions

View File

@@ -288,7 +288,7 @@ class Field(object):
if self.choices:
field_objs = [oldforms.SelectField]
params['choices'] = self.get_choices_default()
params['choices'] = self.flatchoices
else:
field_objs = self.get_manipulator_field_objs()
return (field_objs, params)
@@ -407,6 +407,16 @@ class Field(object):
return self._choices
choices = property(_get_choices)
def _get_flatchoices(self):
flat = []
for choice, value in self.get_choices_default():
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)