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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user