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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-05-14 01:51:14 +00:00
parent 670baf2e48
commit a193f355a8
1 changed files with 7 additions and 6 deletions

View File

@ -512,17 +512,18 @@ than pingbacks, we construct an ``F()`` object to reference the comment count,
and use that ``F()`` object in the query:: and use that ``F()`` object in the query::
>>> from django.db.models import F >>> from django.db.models import F
>>> Entry.objects.filter(n_pingbacks__lt=F('n_comments')) >>> Entry.objects.filter(n_comments__gt=F('n_pingbacks'))
Django supports the use of addition, subtraction, multiplication, Django supports the use of addition, subtraction, multiplication,
division and modulo arithmetic with ``F()`` objects, both with constants division and modulo arithmetic with ``F()`` objects, both with constants
and with other ``F()`` objects. To find all the blog entries with *twice* as and with other ``F()`` objects. To find all the blog entries with more than
many comments as pingbacks, we modify the query:: *twice* as many comments as pingbacks, we modify the query::
>>> Entry.objects.filter(n_pingbacks__lt=F('n_comments') * 2) >>> Entry.objects.filter(n_comments__gt=F('n_pingbacks') * 2)
To find all the entries where the sum of the pingback count and comment count To find all the entries where the rating of the entry is less than the
is greater than the rating of the entry, we would issue the query:: sum of the pingback count and comment count, we would issue the
query::
>>> Entry.objects.filter(rating__lt=F('n_comments') + F('n_pingbacks')) >>> Entry.objects.filter(rating__lt=F('n_comments') + F('n_pingbacks'))