#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)
Change History (6)
comment:1 by , 14 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 14 years ago
comment:2 by , 14 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I think this patch fixes the problem and makes F() objects a bit easier to understand by using gt instead of lt.