diff options
| author | Tim Graham <timograham@gmail.com> | 2012-11-27 18:21:55 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2012-11-27 18:21:55 -0500 |
| commit | ba2adc9c05aa343b58d087a81d9dc84f82b32790 (patch) | |
| tree | dc99b9b94f68045e00f0bf10136d6452af9a3ffd /docs | |
| parent | 7cea123bdebd45dc1bafe02d57a90995e76c28a9 (diff) | |
Fixed #19352 - Added an example in the QuerySet docs.
Thanks colinkeenan for the suggestion.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/db/queries.txt | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 46fabbe5c6..90c06ac66a 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -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( entry__pub_date__year=2008) -In this second example, the first filter restricted the queryset to all those -blogs linked to that particular type of entry. The second filter restricted -the set of blogs *further* to those that are also linked to the second type of -entry. The entries select 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. +Suppose there is only one blog that had both entries containing *"Lennon"* and +entries from 2008, but that none of the entries from 2008 contained *"Lennon"*. +The first query would not return any blogs, but the second query would return +that one blog. + +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 :meth:`~django.db.models.query.QuerySet.exclude`: all the conditions in a |
