diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-01-05 11:47:48 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-01-05 11:47:48 +0000 |
| commit | f747b61c20cb2ab9bcbca2b272f3fba80cf39ac6 (patch) | |
| tree | fd654b89d7a1a492b590e0e34530e45ba837cf39 /django | |
| parent | 062a94ef45e71f525de1c9095aeb3f376feb8232 (diff) | |
Nested query support.
This extends previous functionality that allowed passing Query objects as the
rvals to filters. You can now pass QuerySets, which requires less poking at
opaque attributes. See the documentation of the "__in" lookup type for the
details.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 9 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 5b9f504d2f..2f9f9e24ec 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -641,6 +641,15 @@ class QuerySet(object): """ pass + def as_sql(self): + """ + Returns the internal query's SQL and parameters (as a tuple). + + This is a private (internal) method. The name is chosen to provide + uniformity with other interfaces (in particular, the Query class). + """ + obj = self.values("pk") + return obj.query.as_nested_sql() class ValuesQuerySet(QuerySet): def __init__(self, *args, **kwargs): diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 61c1e51557..432e5e6332 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -313,6 +313,18 @@ class BaseQuery(object): params.extend(self.extra_params) return ' '.join(result), tuple(params) + def as_nested_sql(self): + """ + Perform the same functionality as the as_sql() method, returning an + SQL string and parameters. However, the alias prefixes are bumped + beforehand (in a copy -- the current query isn't changed). + + Used when nesting this query inside another. + """ + obj = self.clone() + obj.bump_prefix() + return obj.as_sql() + def combine(self, rhs, connector): """ Merge the 'rhs' query into the current one (with any 'rhs' effects |
