mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
EmptyQuerySet classes can now be merged with normal querysets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7765 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0e692fda9c
commit
9e23c3c5d9
2 changed files with 20 additions and 0 deletions
|
@ -218,6 +218,8 @@ class QuerySet(object):
|
|||
|
||||
def __and__(self, other):
|
||||
self._merge_sanity_check(other)
|
||||
if isinstance(other, EmptyQuerySet):
|
||||
return other._clone()
|
||||
combined = self._clone()
|
||||
combined.query.combine(other.query, sql.AND)
|
||||
return combined
|
||||
|
@ -225,6 +227,8 @@ class QuerySet(object):
|
|||
def __or__(self, other):
|
||||
self._merge_sanity_check(other)
|
||||
combined = self._clone()
|
||||
if isinstance(other, EmptyQuerySet):
|
||||
return combined
|
||||
combined.query.combine(other.query, sql.OR)
|
||||
return combined
|
||||
|
||||
|
@ -705,6 +709,12 @@ class EmptyQuerySet(QuerySet):
|
|||
super(EmptyQuerySet, self).__init__(model, query)
|
||||
self._result_cache = []
|
||||
|
||||
def __and__(self, other):
|
||||
return self._clone()
|
||||
|
||||
def __or__(self, other):
|
||||
return other._clone()
|
||||
|
||||
def count(self):
|
||||
return 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue