Code

Opened 4 years ago

Closed 4 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:

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')

Attachments (0)

Change History (1)

comment:1 Changed 4 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.