Ticket #7546: 7546.diff
File 7546.diff, 1.7 KB (added by , 16 years ago) |
---|
-
db-api.txt
1708 1708 interested in. Consider the ``Blog``/``Entry`` relationship (``Blog`` to 1709 1709 ``Entry`` is a one-to-many relation). We might be interested in finding blogs 1710 1710 that have an entry which has both *"Lennon"* in the headline and was published 1711 today. Or we might want to find blogs that have an entry with *"Lennon"* in1712 the headline as well as an entry that was published today. Since there are1711 in 2008. Or we might want to find blogs that have an entry with *"Lennon"* in 1712 the headline as well as an entry that was published in 2008. Since there are 1713 1713 multiple entries associated with a single ``Blog``, both of these queries are 1714 1714 possible and make sense in some situations. 1715 1715 … … 1728 1728 1729 1729 That may sound a bit confusing, so hopefully an example will clarify. To 1730 1730 select all blogs that contains entries with *"Lennon"* in the headline and 1731 were published today, we would write::1731 were published in 2008, we would write:: 1732 1732 1733 1733 Blog.objects.filter(entry__headline__contains='Lennon', 1734 entry__pub_date =datetime.date.today())1734 entry__pub_date__year=2008) 1735 1735 1736 1736 To select all blogs that contain an entry with *"Lennon"* in the headline 1737 **as well as** an entry that was published today, we would write::1737 **as well as** an entry that was published in 2008, we would write:: 1738 1738 1739 1739 Blog.objects.filter(entry__headline__contains='Lennon').filter( 1740 entry__pub_date =datetime.date.today())1740 entry__pub_date__year=2008) 1741 1741 1742 1742 In this second example, the first filter restricted the queryset to all those 1743 1743 blogs linked to that particular type of entry. The second filter restricted