#26449: Document that SplitDateTimeWidget requires SplitDateTimeField --------------------------------------+------------------------------------ Reporter: MarysiaLowas | Owner: yakky Type: Cleanup/optimization | Status: assigned Component: Documentation | 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 --------------------------------------+------------------------------------
Comment (by MarysiaLowas): I would like to clarify one thing as I'm not sure I understand the solution. Django Admin, by default uses the `AdminSplitDateTime` widget for model `DateTimeField` with `forms.SplitDateTimeField`. However, when I try to change the default widget with `formfield_overrides` to another widget derived from `SplitDateTimeWidget`, it doesn't work -> validation error. This is especially striking, when I try to override the default `AdminSplitDateTime` widget with the very same `AdminSplitDateTime` widget. (That was just for tests, in fact I wanted to use Django Suit `suit.widgets.SuitSplitDateTimeWidget`) From my investigation, it turned out that Django Admin treats model `DateTimeField` a bit specially. It defines not only the default widget but also the `form_class`. {{{#!python FORMFIELD_FOR_DBFIELD_DEFAULTS = { models.DateTimeField: { 'form_class': forms.SplitDateTimeField, 'widget': widgets.AdminSplitDateTime }, models.DateField: {'widget': widgets.AdminDateWidget}, models.TimeField: {'widget': widgets.AdminTimeWidget}, #... } }}} It works fine, but when I want to override it with: {{{#!python formfield_overrides = { models.DateTimeField: {'widget': suit.widgets.SuitSplitDateTimeWidget}, } }}} The resulting dictionary looks something like that: {{{#!python overrides = { models.DateTimeField: { 'widget': suit.widgets.SuitSplitDateTimeWidget}, models.DateField: {'widget': widgets.AdminDateWidget}, models.TimeField: {'widget': widgets.AdminTimeWidget}, #... } }}} The `form_class` is gone as so the `forms.DateTimeField` is used instead of `forms.SplitDateTimeField` and that causes the validation error. Is it a desired behaviour? If yes, maybe it's good to update also the `formfield_overrides` documentation, not just the docstring for `AdminSplitDateTime` widget? Or maybe it's better to keep the `form_class` value and override just `widget`? BTW, I planned to look into this but I run out of time during Sprints. I'm still quite happy to carry on if needed. -- Ticket URL: <https://code.djangoproject.com/ticket/26449#comment:10> 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.8fb7111a55bb4f840ef0be1c0f32709b%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.