mirror of https://github.com/django/django.git
Fixed #7880 -- Corrected the handling of fields in the admin that specify choices, so that the presence of choices overrides the decision to use a custom admin widget. This is primarily of interest to Date/Time fields. Thanks to camilonova for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8153 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a98d12b1b2
commit
f7d123a731
|
@ -129,6 +129,23 @@ class BaseModelAdmin(object):
|
|||
|
||||
If kwargs are given, they're passed to the form Field's constructor.
|
||||
"""
|
||||
|
||||
# If the field specifies choices, we don't need to look for special
|
||||
# admin widgets - we just need to use a select widget of some kind.
|
||||
if db_field.choices:
|
||||
if db_field.name in self.radio_fields:
|
||||
# If the field is named as a radio_field, use a RadioSelect
|
||||
kwargs['widget'] = widgets.AdminRadioSelect(
|
||||
choices=db_field.get_choices(include_blank=db_field.blank,
|
||||
blank_choice=[('', _('None'))]),
|
||||
attrs={
|
||||
'class': get_ul_class(self.radio_fields[db_field.name]),
|
||||
}
|
||||
)
|
||||
else:
|
||||
# Otherwise, use the default select widget.
|
||||
return db_field.formfield(**kwargs)
|
||||
|
||||
# For DateTimeFields, use a special field and widget.
|
||||
if isinstance(db_field, models.DateTimeField):
|
||||
kwargs['form_class'] = forms.SplitDateTimeField
|
||||
|
@ -177,15 +194,6 @@ class BaseModelAdmin(object):
|
|||
formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site)
|
||||
return formfield
|
||||
|
||||
if db_field.choices and db_field.name in self.radio_fields:
|
||||
kwargs['widget'] = widgets.AdminRadioSelect(
|
||||
choices=db_field.get_choices(include_blank=db_field.blank,
|
||||
blank_choice=[('', _('None'))]),
|
||||
attrs={
|
||||
'class': get_ul_class(self.radio_fields[db_field.name]),
|
||||
}
|
||||
)
|
||||
|
||||
# For any other type of field, just call its formfield() method.
|
||||
return db_field.formfield(**kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue