Code

Changes between Initial Version and Version 2 of Ticket #19135


Ignore:
Timestamp:
10/17/12 00:52:32 (21 months ago)
Author:
claudep
Comment:

No, the example is right. The first filter will apply both conditions on the same join, while the second one will create a separate join for each condition, hence the results might be larger.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19135

    • Property Status changed from new to closed
    • Property Patch needs improvement unset
    • Property Needs tests unset
    • Property Needs documentation unset
    • Property Resolution changed from to invalid
  • Ticket #19135 – Description

    initial v2  
    22 
    33That may sound a bit confusing, so hopefully an example will clarify. To select all blogs that contain entries with both "Lennon" in the headline and that were published in 2008 (the same entry satisfying both conditions), we would write: 
    4  
     4{{{ 
    55Blog.objects.filter(entry__headline__contains='Lennon', 
    66        entry__pub_date__year=2008) 
    7  
     7}}} 
    88To select all blogs that contain an entry with "Lennon" in the headline as well as an entry that was published in 2008, we would write: 
    9  
     9{{{ 
    1010Blog.objects.filter(entry__headline__contains='Lennon').filter( 
    1111        entry__pub_date__year=2008) 
    12  
     12}}} 
    1313From my understanding, the two examples are mixed up: the first example should be for the second explanation and vice versa. First example is a union of two sets: filter(setA, setB), the second example is an intersection of two sets: filter(setA).filter(setB).