#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.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.14d5f01f11b17dbd474094ead71192a9%40djangoproject.com.

Reply via email to