Ticket #2723: booleanwidget_radio.diff
File booleanwidget_radio.diff, 1.8 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
166 166 kwargs['widget'] = widgets.AdminTimeWidget 167 167 return db_field.formfield(**kwargs) 168 168 169 # For BooleanFields, use a special widget. 170 if isinstance(db_field, models.BooleanField): 171 kwargs['widget'] = widgets.AdminBooleanSelect 172 return db_field.formfield(**kwargs) 173 169 174 # For FileFields and ImageFields add a link to the current file. 170 175 if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField): 171 176 kwargs['widget'] = widgets.AdminFileWidget -
django/contrib/admin/widgets.py
46 46 47 47 def __init__(self, attrs={}): 48 48 super(AdminTimeWidget, self).__init__(attrs={'class': 'vTimeField', 'size': '8'}) 49 50 class AdminBooleanSelect(forms.RadioSelect): 51 def __init__(self, attrs=None): 52 choices = ((u'1', _('Yes')), (u'2', _('No'))) 53 super(AdminBooleanSelect, self).__init__(attrs, choices) 54 55 def render(self, name, value, attrs=None, choices=()): 56 try: 57 value = {True: u'1', False: u'2', u'1': u'1', u'2': u'2'}[value] 58 except KeyError: 59 value = u'2' 60 return super(AdminBooleanSelect, self).render(name, value, attrs, choices) 61 62 def value_from_datadict(self, data, files, name): 63 value = data.get(name, None) 64 return {u'1': True, u'2': False, True: True, False: False}.get(value, None) 49 65 50 66 class AdminSplitDateTime(forms.SplitDateTimeWidget): 51 67 """