Opened 7 years ago

Last modified 3 weeks ago

#28048 assigned New feature

Allow generic date views to use related fields as date_field

Reported by: Lefteris Nikoltsios Owned by: Saurabh
Component: Generic views Version: 1.11
Severity: Normal Keywords:
Cc: Jaap Roes Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

For example if we have some models like that:

class Blog(models.Model):
    title = models.TextField()
    pubdate = models.DateField()

class Article(models.Model):
    blog = models.ForeignKey(Blog)
    title = models.TextFIeld()
    pubdate = models.DateField()

the following view:

from django.views.generic.dates import MonthArchiveView

from .models import Article


class ArticleMonthArchiveView(MonthArchiveView):
    queryset = Article.objects.all()
    date_field = 'blog__pub_date'

will raise FieldDoesNotExist.

Change History (7)

comment:1 by Lefteris Nikoltsios, 7 years ago

Has patch: set

comment:2 by Tim Graham, 7 years ago

Patch needs improvement: set
Summary: Generic date views don't work with related fields as date_fieldAllow generic date views to use related fields as date_field
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

comment:3 by Lefteris Nikoltsios, 7 years ago

Patch needs improvement: unset

comment:4 by Carlton Gibson, 6 years ago

Patch needs improvement: set

comment:5 by Jaap Roes, 3 years ago

Cc: Jaap Roes added

I created issue #32846 which was marked as a duplicate. Looking at the patch provided for this ticket is seems that the most difficult part is the lack of an "official" way of resolving "field paths" like blog__pub_date to fields. Django admin provides some utility methods, but since it is a contrib app it cannot be used in other "core" Django code.

Is there a separate ticket that tracks this? (I couldn't find one.) The addition of a canonical way to resolve field paths could also be helpful for 3rd party apps, for example django-filter has it's own implementation: https://github.com/carltongibson/django-filter/blob/f507201addfb7f105e722573f3ced4b4a9870526/django_filters/utils.py#L143, and I'm certain there are others.

comment:6 by Mariusz Felisiak, 12 months ago

Owner: Lefteris Nikoltsios removed
Status: assignednew

comment:7 by Saurabh , 3 weeks ago

Owner: set to Saurabh
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top