Code

Ticket #9148: custom_widget.diff

File custom_widget.diff, 4.0 KB (added by gogna, 5 years ago)
Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 9699)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -64,51 +64,62 @@
6                 # Otherwise, use the default select widget.
7                 return db_field.formfield(**kwargs)
8 
9+        defaults = {}
10         # For DateTimeFields, use a special field and widget.
11         if isinstance(db_field, models.DateTimeField):
12-            kwargs['form_class'] = forms.SplitDateTimeField
13-            kwargs['widget'] = widgets.AdminSplitDateTime()
14-            return db_field.formfield(**kwargs)
15+            defaults['form_class'] = forms.SplitDateTimeField
16+            defaults['widget'] = widgets.AdminSplitDateTime()
17+            defaults.update(kwargs)
18+           
19+            return db_field.formfield(**defaults)
20 
21         # For DateFields, add a custom CSS class.
22         if isinstance(db_field, models.DateField):
23-            kwargs['widget'] = widgets.AdminDateWidget
24-            return db_field.formfield(**kwargs)
25+            defaults['widget'] = widgets.AdminDateWidget
26+            defaults.update(kwargs)
27+            return db_field.formfield(**defaults)
28 
29         # For TimeFields, add a custom CSS class.
30         if isinstance(db_field, models.TimeField):
31-            kwargs['widget'] = widgets.AdminTimeWidget
32-            return db_field.formfield(**kwargs)
33+            defaults['widget'] = widgets.AdminTimeWidget
34+            defaults.update(kwargs)
35+            return db_field.formfield(**defaults)
36         
37         # For TextFields, add a custom CSS class.
38         if isinstance(db_field, models.TextField):
39-            kwargs['widget'] = widgets.AdminTextareaWidget
40-            return db_field.formfield(**kwargs)
41+            defaults['widget'] = widgets.AdminTextareaWidget
42+            defaults.update(kwargs)
43+            return db_field.formfield(**defaults)
44         
45         # For URLFields, add a custom CSS class.
46         if isinstance(db_field, models.URLField):
47-            kwargs['widget'] = widgets.AdminURLFieldWidget
48-            return db_field.formfield(**kwargs)
49+            defaults['widget'] = widgets.AdminURLFieldWidget
50+            defaults.update(kwargs)
51+            return db_field.formfield(**defaults)
52         
53         # For IntegerFields, add a custom CSS class.
54         if isinstance(db_field, models.IntegerField):
55-            kwargs['widget'] = widgets.AdminIntegerFieldWidget
56-            return db_field.formfield(**kwargs)
57+            defaults['widget'] = widgets.AdminIntegerFieldWidget
58+            defaults.update(kwargs)
59+            return db_field.formfield(**defaults)
60 
61         # For CommaSeparatedIntegerFields, add a custom CSS class.
62         if isinstance(db_field, models.CommaSeparatedIntegerField):
63-            kwargs['widget'] = widgets.AdminCommaSeparatedIntegerFieldWidget
64-            return db_field.formfield(**kwargs)
65+            defaults['widget'] = widgets.AdminCommaSeparatedIntegerFieldWidget
66+            defaults.update(kwargs)
67+            return db_field.formfield(**defaults)
68 
69         # For TextInputs, add a custom CSS class.
70         if isinstance(db_field, models.CharField):
71-            kwargs['widget'] = widgets.AdminTextInputWidget
72-            return db_field.formfield(**kwargs)
73+            defaults['widget'] = widgets.AdminTextInputWidget
74+            defaults.update(kwargs)
75+            return db_field.formfield(**defaults)
76     
77         # For FileFields and ImageFields add a link to the current file.
78         if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField):
79-            kwargs['widget'] = widgets.AdminFileWidget
80-            return db_field.formfield(**kwargs)
81+            defaults['widget'] = widgets.AdminFileWidget
82+            defaults.update(kwargs)
83+            return db_field.formfield(**defaults)
84 
85         # For ForeignKey or ManyToManyFields, use a special widget.
86         if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):