#26449: formfield_overrides doesn't work for models.DateTimeField with SplitDateTimeWidget -------------------------------+------------------------------------ Reporter: MarysiaLowas | Owner: nobody Type: Uncategorized | Status: new Component: contrib.admin | Version: 1.9 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+------------------------------------ Changes (by yakky):
* needs_better_patch: => 0 * stage: Unreviewed => Accepted * needs_tests: => 0 * needs_docs: => 0 Old 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. New 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': 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. -- Comment: 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 -- Ticket URL: <https://code.djangoproject.com/ticket/26449#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/070.54c31461e72f781b8b9fdcfbac57cbb1%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.