Ticket #9148: custom_widget.diff
File custom_widget.diff, 4.0 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
64 64 # Otherwise, use the default select widget. 65 65 return db_field.formfield(**kwargs) 66 66 67 defaults = {} 67 68 # For DateTimeFields, use a special field and widget. 68 69 if isinstance(db_field, models.DateTimeField): 69 kwargs['form_class'] = forms.SplitDateTimeField 70 kwargs['widget'] = widgets.AdminSplitDateTime() 71 return db_field.formfield(**kwargs) 70 defaults['form_class'] = forms.SplitDateTimeField 71 defaults['widget'] = widgets.AdminSplitDateTime() 72 defaults.update(kwargs) 73 74 return db_field.formfield(**defaults) 72 75 73 76 # For DateFields, add a custom CSS class. 74 77 if isinstance(db_field, models.DateField): 75 kwargs['widget'] = widgets.AdminDateWidget 76 return db_field.formfield(**kwargs) 78 defaults['widget'] = widgets.AdminDateWidget 79 defaults.update(kwargs) 80 return db_field.formfield(**defaults) 77 81 78 82 # For TimeFields, add a custom CSS class. 79 83 if isinstance(db_field, models.TimeField): 80 kwargs['widget'] = widgets.AdminTimeWidget 81 return db_field.formfield(**kwargs) 84 defaults['widget'] = widgets.AdminTimeWidget 85 defaults.update(kwargs) 86 return db_field.formfield(**defaults) 82 87 83 88 # For TextFields, add a custom CSS class. 84 89 if isinstance(db_field, models.TextField): 85 kwargs['widget'] = widgets.AdminTextareaWidget 86 return db_field.formfield(**kwargs) 90 defaults['widget'] = widgets.AdminTextareaWidget 91 defaults.update(kwargs) 92 return db_field.formfield(**defaults) 87 93 88 94 # For URLFields, add a custom CSS class. 89 95 if isinstance(db_field, models.URLField): 90 kwargs['widget'] = widgets.AdminURLFieldWidget 91 return db_field.formfield(**kwargs) 96 defaults['widget'] = widgets.AdminURLFieldWidget 97 defaults.update(kwargs) 98 return db_field.formfield(**defaults) 92 99 93 100 # For IntegerFields, add a custom CSS class. 94 101 if isinstance(db_field, models.IntegerField): 95 kwargs['widget'] = widgets.AdminIntegerFieldWidget 96 return db_field.formfield(**kwargs) 102 defaults['widget'] = widgets.AdminIntegerFieldWidget 103 defaults.update(kwargs) 104 return db_field.formfield(**defaults) 97 105 98 106 # For CommaSeparatedIntegerFields, add a custom CSS class. 99 107 if isinstance(db_field, models.CommaSeparatedIntegerField): 100 kwargs['widget'] = widgets.AdminCommaSeparatedIntegerFieldWidget 101 return db_field.formfield(**kwargs) 108 defaults['widget'] = widgets.AdminCommaSeparatedIntegerFieldWidget 109 defaults.update(kwargs) 110 return db_field.formfield(**defaults) 102 111 103 112 # For TextInputs, add a custom CSS class. 104 113 if isinstance(db_field, models.CharField): 105 kwargs['widget'] = widgets.AdminTextInputWidget 106 return db_field.formfield(**kwargs) 114 defaults['widget'] = widgets.AdminTextInputWidget 115 defaults.update(kwargs) 116 return db_field.formfield(**defaults) 107 117 108 118 # For FileFields and ImageFields add a link to the current file. 109 119 if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField): 110 kwargs['widget'] = widgets.AdminFileWidget 111 return db_field.formfield(**kwargs) 120 defaults['widget'] = widgets.AdminFileWidget 121 defaults.update(kwargs) 122 return db_field.formfield(**defaults) 112 123 113 124 # For ForeignKey or ManyToManyFields, use a special widget. 114 125 if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):