Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#13532 closed (fixed)

Error in F() object docs

Reported by: Erik Wognsen Owned by: Erik Wognsen
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 Erik Wognsen 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Alex Gaynor

milestone: 1.2
Triage Stage: UnreviewedAccepted

Changed 7 years ago by Erik Wognsen

Attachment: Fdoc.diff added

comment:2 Changed 7 years ago by Erik Wognsen

Has patch: set
Owner: changed from nobody to Erik Wognsen
Status: newassigned

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 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

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

comment:4 Changed 7 years ago by Russell Keith-Magee

(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 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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