Ticket #3283: empty_queryset.patch
File empty_queryset.patch, 1.8 KB (added by , 18 years ago) |
---|
-
db/models/manager.py
1 from django.db.models.query import QuerySet 1 from django.db.models.query import QuerySet, EmptyQuerySet 2 2 from django.dispatch import dispatcher 3 3 from django.db.models import signals 4 4 from django.db.models.fields import FieldDoesNotExist … … 41 41 ####################### 42 42 # PROXIES TO QUERYSET # 43 43 ####################### 44 45 def get_empty_query_set(self): 46 return EmptyQuerySet(self.model) 44 47 45 48 def get_query_set(self): 46 49 """Returns a new QuerySet object. Subclasses can override this method 47 50 to easily customise the behaviour of the Manager. 48 51 """ 49 52 return QuerySet(self.model) 53 54 def none(self): 55 return self.get_empty_query_set() 50 56 51 57 def all(self): 52 58 return self.get_query_set() -
db/models/query.py
562 562 c._kind = self._kind 563 563 c._order = self._order 564 564 return c 565 566 class EmptyQuerySet(QuerySet): 567 def __init__(self, model=None): 568 super(EmptyQuerySet,self).__init__(model) 569 self._result_cache = [] 570 571 def iterator(self): 572 raise StopIteration 573 574 def count(self): 575 return 0 576 577 def delete(self): 578 pass 565 579 580 def _clone(self, klass=None, **kwargs): 581 c = super(EmptyQuerySet, self)._clone(klass, **kwargs) 582 c._result_cache = [] 583 return c 584 566 585 class QOperator(object): 567 586 "Base class for QAnd and QOr" 568 587 def __init__(self, *args):