Opened 14 years ago

Closed 14 years ago

#12891 closed (wontfix)

wishlist: allow .dates() query to span relations

Reported by: Tilman Koschnick Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

At the moment, the dates() query only accepts field parameters that do not span relations. It would be nice if support for more complex cases was added, so that a query like this would be possible:

queryset.dates('foreignkey__date', 'year')

I currently use the following hack to work around this:

    # check if date_field spans relations
    fields = date_field.split('__')
    for field in fields[:-1]:
        relation_field = getattr(queryset.model, field)
        queryset = relation_field.field.rel.to.objects.all()
    dates = queryset.dates(fields[-1], 'year')

Change History (1)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: newclosed

I'm not convinced that your "workaround" isn't the right solution. If you want a list of dates on a model, you should be querying that model. I'm not sure I see the advantage to pushing the join through the dates() operator.

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