Ticket #7546: 7546.diff

File 7546.diff, 1.7 KB (added by Dan Watson, 16 years ago)

doc update

  • db-api.txt

     
    17081708interested in. Consider the ``Blog``/``Entry`` relationship (``Blog`` to
    17091709``Entry`` is a one-to-many relation). We might be interested in finding blogs
    17101710that 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"* in
    1712 the headline as well as an entry that was published today. Since there are
     1711in 2008. Or we might want to find blogs that have an entry with *"Lennon"* in
     1712the headline as well as an entry that was published in 2008. Since there are
    17131713multiple entries associated with a single ``Blog``, both of these queries are
    17141714possible and make sense in some situations.
    17151715
     
    17281728
    17291729That may sound a bit confusing, so hopefully an example will clarify. To
    17301730select all blogs that contains entries with *"Lennon"* in the headline and
    1731 were published today, we would write::
     1731were published in 2008, we would write::
    17321732
    17331733    Blog.objects.filter(entry__headline__contains='Lennon',
    1734             entry__pub_date=datetime.date.today())
     1734            entry__pub_date__year=2008)
    17351735
    17361736To 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::
    17381738
    17391739    Blog.objects.filter(entry__headline__contains='Lennon').filter(
    1740             entry__pub_date=datetime.date.today())
     1740            entry__pub_date__year=2008)
    17411741
    17421742In this second example, the first filter restricted the queryset to all those
    17431743blogs linked to that particular type of entry. The second filter restricted
Back to Top