Opened 8 years ago
Last modified 10 months 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 , 8 years ago
Has patch: | set |
---|
comment:2 by , 8 years ago
Patch needs improvement: | set |
---|---|
Summary: | Generic date views don't work with related fields as date_field → Allow generic date views to use related fields as date_field |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → New feature |
comment:3 by , 8 years ago
Patch needs improvement: | unset |
---|
comment:4 by , 7 years ago
Patch needs improvement: | set |
---|
comment:5 by , 3 years ago
Cc: | 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 , 21 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:7 by , 10 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
PR