mirror of
https://github.com/django/django.git
synced 2025-09-26 20:19:16 +00:00
Fixed #11402: added a QuerySet.exists()
method. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9f70783b14
commit
b79702b2de
6 changed files with 31 additions and 28 deletions
|
@ -2,20 +2,13 @@
|
|||
The main QuerySet implementation. This provides the public API for the ORM.
|
||||
"""
|
||||
|
||||
try:
|
||||
set
|
||||
except NameError:
|
||||
from sets import Set as set # Python 2.3 fallback
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from django.db import connection, transaction, IntegrityError
|
||||
from django.db.models.aggregates import Aggregate
|
||||
from django.db.models.fields import DateField
|
||||
from django.db.models.query_utils import Q, select_related_descend, CollectedObjects, CyclicDependency, deferred_class_factory
|
||||
from django.db.models import signals, sql
|
||||
|
||||
|
||||
# Used to control how many objects are worked with at once in some cases (e.g.
|
||||
# when deleting objects).
|
||||
CHUNK_SIZE = 100
|
||||
|
@ -444,6 +437,11 @@ class QuerySet(object):
|
|||
return query.execute_sql(None)
|
||||
_update.alters_data = True
|
||||
|
||||
def exists(self):
|
||||
if self._result_cache is None:
|
||||
return self.query.has_results()
|
||||
return bool(self._result_cache)
|
||||
|
||||
##################################################
|
||||
# PUBLIC METHODS THAT RETURN A QUERYSET SUBCLASS #
|
||||
##################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue