diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-10-24 00:28:39 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-10-24 00:28:39 +0000 |
| commit | b79702b2deec4ca3c625e5bffe46fa976c3c4e5f (patch) | |
| tree | 2031b1d908ca03f650669b04effee8a872632e86 /django/db/models/sql | |
| parent | 9f70783b149105dfd37027504976f9526caeeae0 (diff) | |
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
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 23f99e41ad..136c97f639 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -8,7 +8,6 @@ all about the internals of models in order to get the information it needs. """ from copy import deepcopy - from django.utils.tree import Node from django.utils.datastructures import SortedDict from django.utils.encoding import force_unicode @@ -24,11 +23,6 @@ from django.core.exceptions import FieldError from datastructures import EmptyResultSet, Empty, MultiJoin from constants import * -try: - set -except NameError: - from sets import Set as set # Python 2.3 fallback - __all__ = ['Query', 'BaseQuery'] class BaseQuery(object): @@ -384,6 +378,15 @@ class BaseQuery(object): return number + def has_results(self): + q = self.clone() + q.add_extra({'a': 1}, None, None, None, None, None) + q.add_fields(()) + q.set_extra_mask(('a',)) + q.set_aggregate_mask(()) + q.clear_ordering() + return bool(q.execute_sql()) + def as_sql(self, with_limits=True, with_col_aliases=False): """ Creates the SQL for this query. Returns the SQL string and list of |
