Opened 3 years ago

Closed 3 years ago

#32846 closed New feature (duplicate)

DateMixin.uses_datetime_field does not work when date_field is defined on a related model

Reported by: Jaap Roes Owned by: nobody
Component: Generic views Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Today I had the need to create a date based archive for a model that stores the date on a related model:

class Bar(models.Model):
    date = models.DateField()

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

with a view like this:

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)

Change History (1)

comment:1 by Carlton Gibson, 3 years ago

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top