Opened 15 years ago

Closed 15 years ago

Last modified 13 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: no UI/UX: no

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 15 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Alex Gaynor, 15 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

by Erik Wognsen, 15 years ago

Attachment: Fdoc.diff added

comment:2 by Erik Wognsen, 15 years ago

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

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

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

milestone: 1.2

Milestone 1.2 deleted

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