Django

Code

Changeset 7765

Show
Ignore:
Timestamp:
06/26/08 06:42:12 (5 months ago)
Author:
mtredinnick
Message:

EmptyQuerySet? classes can now be merged with normal querysets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r7763 r7765  
    219219    def __and__(self, other): 
    220220        self._merge_sanity_check(other) 
     221        if isinstance(other, EmptyQuerySet): 
     222            return other._clone() 
    221223        combined = self._clone() 
    222224        combined.query.combine(other.query, sql.AND) 
     
    226228        self._merge_sanity_check(other) 
    227229        combined = self._clone() 
     230        if isinstance(other, EmptyQuerySet): 
     231            return combined 
    228232        combined.query.combine(other.query, sql.OR) 
    229233        return combined 
     
    706710        self._result_cache = [] 
    707711 
     712    def __and__(self, other): 
     713        return self._clone() 
     714 
     715    def __or__(self, other): 
     716        return other._clone() 
     717 
    708718    def count(self): 
    709719        return 0 
  • django/trunk/tests/regressiontests/queries/models.py

    r7764 r7765  
    782782[] 
    783783 
     784Empty querysets can be merged with others. 
     785>>> Note.objects.none() | Note.objects.all() 
     786[<Note: n1>, <Note: n2>, <Note: n3>] 
     787>>> Note.objects.all() | Note.objects.none() 
     788[<Note: n1>, <Note: n2>, <Note: n3>] 
     789>>> Note.objects.none() & Note.objects.all() 
     790[] 
     791>>> Note.objects.all() & Note.objects.none() 
     792[] 
     793 
    784794"""} 
    785795