Opened 9 years ago
Last modified 9 years ago
#26449 closed Cleanup/optimization
formfield_overrides doesn't work for models.DateTimeField with SplitDateTimeWidget — at Initial Version
Reported by: | Marysia Lowas-Rzechonek | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When you override the default widget used in Django Admin for models.DateTimeField using formfield_overrides with any widget that derives from SplitDateTimeWidget, the form will not pass the validation with 'Enter a valid date/time.' error message.
It seems that when updating the default formfield_overrides dict, it overrides the default values instead of merging them. At present, it seems to affect only the DateTimeField.
So, this code will trigger the error: 'Enter a valid date/time.'
formfield_overrides = {models.DateTimeField: {widgets.AdminSplitDateTime},}
And this code will be fine:
formfield_overrides = {models.DateTimeField: {'form_class': forms.SplitDateTimeField,'widget': widgets.AdminSplitDateTime},}
The problem in django/contrib/admin/option.py around line 117.