Ticket #19352: 19352.diff

File 19352.diff, 1.6 KB (added by Tim Graham, 12 years ago)
  • docs/topics/db/queries.txt

    diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
    index 46fabbe..8c84726 100644
    a b To select all blogs that contain an entry with *"Lennon"* in the headline  
    575575    Blog.objects.filter(entry__headline__contains='Lennon').filter(
    576576            entry__pub_date__year=2008)
    577577
    578 In this second example, the first filter restricted the queryset to all those
    579 blogs linked to that particular type of entry. The second filter restricted
    580 the set of blogs *further* to those that are also linked to the second type of
    581 entry. The entries select by the second filter may or may not be the same as
    582 the entries in the first filter. We are filtering the ``Blog`` items with each
    583 filter statement, not the ``Entry`` items.
     578Suppose there is only one blog that had both entries containing *"Lennon"* and
     579entries from 2008, but that none of the entries from 2008 contained *"Lennon"*.
     580Then, the first query would not return any blogs, but the second query would
     581return that one blog.
     582
     583In the second example, the first filter restricted the queryset to all those
     584blogs linked to entries with *"Lennon"* in the headline. The second filter
     585restricted the set of blogs *further* to those that are also linked to entries
     586that were published in 2008. The entries selected by the second filter may or
     587may not be the same as the entries in the first filter. We are filtering the
     588``Blog`` items with each filter statement, not the ``Entry`` items.
    584589
    585590All of this behavior also applies to
    586591:meth:`~django.db.models.query.QuerySet.exclude`: all the conditions in a
Back to Top