[Django] #27304: Django 1.10 onwards broke previous behaviour for models.DateTimeField() in Admin

15 views
Skip to first unread message

Django

unread,
Oct 1, 2016, 11:54:37 PM10/1/16
to django-...@googlegroups.com
#27304: Django 1.10 onwards broke previous behaviour for models.DateTimeField() in
Admin
-------------------------+-------------------------------------------------
Reporter: Kegan | Owner: nobody
Gan |
Type: Bug | Status: new
Component: | Version: 1.10
contrib.admin | Keywords: model admin datetime
Severity: Normal | formfield_overrides AdminDateWidget widget
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
In Django 1.9 and prior, we can use a date widget in Admin for a
`datetime` field. Specifically, we can override the default `datetime`
widget in Admin using `AdminDateWidget`. In this way, user are only
require to enter a ''date''. The ''time'' will be default 0h 0m 0s.

From Django 1.10 onwards, this behaviour has break. Now, there is an error
`Enter a list of values.` on save in Admin.

Example code.

Model:
{{{
class Highlight(models.Model):
end_at = models.DateTimeField()

def save(self, *args, **kwargs):
# Add 23 hours, 59 minutes, 59 seconds to end_at so that it
represent end of day.
extratime = timedelta(hours=23, minutes=59, seconds=59)
if self.end_at:
self.end_at = self.end_at + extratime
super(Highlight, self).save(*args, **kwargs)
}}}

Admin:
{{{
class HighlightAdmin(admin.ModelAdmin):
formfield_overrides = {
models.DateTimeField: {'widget': widgets.AdminDateWidget},
}
}}}

Now there is no easy way to let user only input the ''date'' part of
`datetime`field in Admin.

--
Ticket URL: <https://code.djangoproject.com/ticket/27304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 2, 2016, 2:06:38 PM10/2/16
to django-...@googlegroups.com
#27304: Django 1.10 onwards broke previous behaviour for models.DateTimeField() in
Admin
-------------------------------------+-------------------------------------
Reporter: Kegan Gan | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: model admin | Triage Stage:
datetime formfield_overrides | Unreviewed
AdminDateWidget widget |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can you [https://docs.djangoproject.com/en/dev/internals/contributing
/triaging-tickets/#bisecting-a-regression bisect] to find where the
behavior changed? Without looking into the details, I'm not immediately
convinced we should treat this as a bug and provide backwards-
compatibility for it, but we'll see.

--
Ticket URL: <https://code.djangoproject.com/ticket/27304#comment:1>

Django

unread,
Oct 3, 2016, 12:59:26 PM10/3/16
to django-...@googlegroups.com
#27304: Django 1.10 onwards broke previous behaviour for models.DateTimeField() in
Admin
-------------------------------------+-------------------------------------
Reporter: Kegan Gan | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: invalid

Keywords: model admin | Triage Stage:
datetime formfield_overrides | Unreviewed
AdminDateWidget widget |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Bisected to b9290b1d49538c1092b59c41e6046b11c25ecafb. To adapt your code,
you must add `'form_class': forms.DateField` to the override.

--
Ticket URL: <https://code.djangoproject.com/ticket/27304#comment:2>

Django

unread,
Oct 4, 2016, 10:37:12 PM10/4/16
to django-...@googlegroups.com
#27304: Django 1.10 onwards broke previous behaviour for models.DateTimeField() in
Admin
-------------------------------------+-------------------------------------
Reporter: Kegan Gan | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: invalid
Keywords: model admin | Triage Stage:
datetime formfield_overrides | Unreviewed
AdminDateWidget widget |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Kegan Gan):

Thanks Tim! It worked.

For reference, to override admin widget, use the following:

{{{
formfield_overrides = {
models.DateTimeField: {'form_class': forms.DateTimeField,
'widget': widgets.AdminDateWidget},
}
}}}

Also refer to #26449.

--
Ticket URL: <https://code.djangoproject.com/ticket/27304#comment:3>

Reply all
Reply to author
Forward
0 new messages