Opened 6 years ago

Closed 6 years ago

#12891 closed (wontfix)

wishlist: allow .dates() query to span relations

Reported by: til 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: UI/UX:


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 =
    dates = queryset.dates(fields[-1], 'year')

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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