| 128 | field_type_overrides = { models.DateTimeField: { 'form_class': forms.SplitDateTimeField, |
| 129 | 'widget': widgets.AdminSplitDateTime }, |
| 130 | models.DateField: { 'widget': widgets.AdminDateWidget }, |
| 131 | models.TimeField: { 'widget': widgets.AdminTimeWidget }, |
| 132 | models.TextField: { 'widget': widgets.AdminTextareaWidget }, |
| 133 | models.URLField: { 'widget': widgets.AdminURLFieldWidget }, |
| 134 | models.IntegerField: { 'widget': widgets.AdminIntegerFieldWidget }, |
| 135 | models.CharField: { 'widget': widgets.AdminTextInputWidget }, |
| 136 | models.ImageField: { 'widget': widgets.AdminFileWidget }, |
| 137 | models.FileField: { 'widget': widgets.AdminFileWidget }, |
| 138 | } |
| 139 | |
153 | | # For DateTimeFields, use a special field and widget. |
154 | | if isinstance(db_field, models.DateTimeField): |
155 | | kwargs['form_class'] = forms.SplitDateTimeField |
156 | | kwargs['widget'] = widgets.AdminSplitDateTime() |
157 | | return db_field.formfield(**kwargs) |
| 165 | if db_field.__class__ in self.field_type_overrides: |
| 166 | return dbfield.formfield(**dict(kwargs, **self.field_type_overrides[db_field.__class__])) |
159 | | # For DateFields, add a custom CSS class. |
160 | | if isinstance(db_field, models.DateField): |
161 | | kwargs['widget'] = widgets.AdminDateWidget |
162 | | return db_field.formfield(**kwargs) |
163 | | |
164 | | # For TimeFields, add a custom CSS class. |
165 | | if isinstance(db_field, models.TimeField): |
166 | | kwargs['widget'] = widgets.AdminTimeWidget |
167 | | return db_field.formfield(**kwargs) |
168 | | |
169 | | # For TextFields, add a custom CSS class. |
170 | | if isinstance(db_field, models.TextField): |
171 | | kwargs['widget'] = widgets.AdminTextareaWidget |
172 | | return db_field.formfield(**kwargs) |
173 | | |
174 | | # For URLFields, add a custom CSS class. |
175 | | if isinstance(db_field, models.URLField): |
176 | | kwargs['widget'] = widgets.AdminURLFieldWidget |
177 | | return db_field.formfield(**kwargs) |
178 | | |
179 | | # For IntegerFields, add a custom CSS class. |
180 | | if isinstance(db_field, models.IntegerField): |
181 | | kwargs['widget'] = widgets.AdminIntegerFieldWidget |
182 | | return db_field.formfield(**kwargs) |
183 | | |
184 | | # For TextInputs, add a custom CSS class. |
185 | | if isinstance(db_field, models.CharField): |
186 | | kwargs['widget'] = widgets.AdminTextInputWidget |
187 | | return db_field.formfield(**kwargs) |
188 | | |
189 | | # For FileFields and ImageFields add a link to the current file. |
190 | | if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField): |
191 | | kwargs['widget'] = widgets.AdminFileWidget |
192 | | return db_field.formfield(**kwargs) |
193 | | |