[Django] #32846: DateMixin.uses_datetime_field does not work when date_field is defined on a related model

5 views
Skip to first unread message

Django

unread,
Jun 14, 2021, 9:22:33 AM6/14/21
to django-...@googlegroups.com
#32846: DateMixin.uses_datetime_field does not work when date_field is defined on a
related model
-----------------------------------------+------------------------
Reporter: Jaap Roes | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Today I had the need to create a date based archive for a model that
stores the date on a related model:

{{{#!python
class Bar(models.Model):
date = models.DateField()

class Foo(models.Model):
bar = models.OneToOneField(Bar, on_delete=models.CASCADE)
}}}

with a view like this:

{{{#!python
class FooMonthArchiveView(MonthArchiveView):
queryset = Foo.objects.all()
date_field = "bar__date"
}}}

Django raises an error from `uses_datetime_field` because `bar__date`
isn't a field on the `Foo` model.

By overriding `uses_datetime_field` to just return `False` things seem to
work just fine.

I'll mark this as a new feature as it isn't explicitly documented that
this should work, and hasn't worked for quite a while (for at least since
whenever the `uses_datetime_field property` was introduced)

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

Django

unread,
Jun 15, 2021, 3:24:30 AM6/15/21
to django-...@googlegroups.com
#32846: DateMixin.uses_datetime_field does not work when date_field is defined on a
related model
-------------------------------+--------------------------------------

Reporter: Jaap Roes | Owner: nobody
Type: New feature | Status: closed

Component: Generic views | Version: dev
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

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


Comment:

This is a duplicate of #28048. There was a PR there, that needed a little
work but could be feasible if you wanted to pick it up.

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

Reply all
Reply to author
Forward
0 new messages