Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13532 closed (fixed)

Error in F() object docs

Reported by: erw Owned by: erw
Component: Documentation Version:
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

http://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-reference-fields-on-the-model says:

"To find all the blog entries with twice as many comments as pingbacks, we modify the query:"

>>> Entry.objects.filter(n_pingbacks__lt=F('n_comments') * 2)

But the query should in fact have been:

>>> Entry.objects.filter(n_pingbacks=F('n_comments') / 2)

And to find entries with at least twice as many comments as pingbacks:

>>> Entry.objects.filter(n_pingbacks__lte=F('n_comments') / 2)

It would probably be easier to understand the sentences where comments come before pingbacks ("twice as many comments as pingbacks"), if they had the same order in the query. Again, to find entries with at least twice as many comments as pingbacks:

>>> Entry.objects.filter(n_comments__gte=F('n_pingbacks') * 2)

Attachments (1)

Fdoc.diff (1.1 KB) - added by erw 4 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by Alex

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by erw

comment:2 Changed 4 years ago by erw

  • Has patch set
  • Owner changed from nobody to erw
  • Status changed from new to assigned

I think this patch fixes the problem and makes F() objects a bit easier to understand by using gt instead of lt.

comment:3 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [13254]) Fixed #13532 -- Corrected and clarified examples in F() docs. Thanks to erw for the report and patch.

comment:4 Changed 4 years ago by russellm

(In [13255]) [1.1.X] Fixed #13532 -- Corrected and clarified examples in F() docs. Thanks to erw for the report and patch.

Backport of r13254 from trunk.

comment:5 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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.