Code

Opened 2 years ago

Closed 2 years ago

#17748 closed Bug (invalid)

Wrong lookup in the aggregation examples

Reported by: yliharma Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal 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

The example lookup in https://docs.djangoproject.com/en/1.3/topics/db/aggregation/#order-of-annotate-and-filter-clauses
is wrong:

>>> Publisher.objects.annotate(num_books=Count('book')).filter(book__rating__gt=3.0)
and the query:

>>> Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('book'))

because the model Publisher doesn't contain any ForeignKey to the model Book (while the reverse is True).
It should be:

>>> Publisher.objects.annotate(num_books=Count('book')).filter(book_set__rating__gt=3.0)
and the query:

>>> Publisher.objects.filter(book_set__rating__gt=3.0).annotate(num_books=Count('book'))

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by ramiro

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

No, the parts separated by '__' of a lookup that spans relationships use the lowercase model names, not the <model>_set notation. See https://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships

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.