Fixed #19352 - Added an example in the QuerySet docs.

Thanks colinkeenan for the suggestion.
This commit is contained in:
Tim Graham 2012-11-27 18:21:55 -05:00
parent 7cea123bde
commit ba2adc9c05
1 changed files with 11 additions and 6 deletions

View File

@ -575,12 +575,17 @@ To select all blogs that contain an entry with *"Lennon"* in the headline
Blog.objects.filter(entry__headline__contains='Lennon').filter( Blog.objects.filter(entry__headline__contains='Lennon').filter(
entry__pub_date__year=2008) entry__pub_date__year=2008)
In this second example, the first filter restricted the queryset to all those Suppose there is only one blog that had both entries containing *"Lennon"* and
blogs linked to that particular type of entry. The second filter restricted entries from 2008, but that none of the entries from 2008 contained *"Lennon"*.
the set of blogs *further* to those that are also linked to the second type of The first query would not return any blogs, but the second query would return
entry. The entries select by the second filter may or may not be the same as that one blog.
the entries in the first filter. We are filtering the ``Blog`` items with each
filter statement, not the ``Entry`` items. In the second example, the first filter restricts the queryset to all those
blogs linked to entries with *"Lennon"* in the headline. The second filter
restricts the set of blogs *further* to those that are also linked to entries
that were published in 2008. The entries selected by the second filter may or
may not be the same as the entries in the first filter. We are filtering the
``Blog`` items with each filter statement, not the ``Entry`` items.
All of this behavior also applies to All of this behavior also applies to
:meth:`~django.db.models.query.QuerySet.exclude`: all the conditions in a :meth:`~django.db.models.query.QuerySet.exclude`: all the conditions in a