Opened 9 years ago
Last modified 9 years ago
#26449 closed Cleanup/optimization
formfield_overrides doesn't work for models.DateTimeField with SplitDateTimeWidget — at Version 1
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 (last modified by )
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': 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.
Change History (1)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Tested according to the OP description (minor edit made to the description). I'm able to reproduce this on 1.9 and master. 1.8 is not affeced