From 43b35a0a633249a068281c849aae54e8ed3f5c3a Mon Sep 17 00:00:00 2001
From: Sebastian Noack <sebastian.noack@gmail.com>
Date: Thu, 29 May 2008 14:15:57 +0200
Subject: [PATCH] Added test and documentation for sub-selects.

---
 docs/db-api.txt                         |   12 ++++++++++++
 tests/regressiontests/queries/models.py |    4 ++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/docs/db-api.txt b/docs/db-api.txt
index 405ed87..07095fa 100644
--- a/docs/db-api.txt
+++ b/docs/db-api.txt
@@ -1368,6 +1368,18 @@ SQL equivalent::
 
     SELECT ... WHERE id IN (1, 3, 4);
 
+.. note::
+    It is possible to realize sub-selects by using ``in`` lookup.
+
+    Example::
+
+        Entry.objects.filter(
+            blog__in=Blog.objects.filter(name='Cheddar Talk').values('pk').query)
+
+    SQL equivalent::
+
+        SELECT ... WHERE id IN (SELECT id FROM ... WHERE name = 'Cheddar Talk');
+
 startswith
 ~~~~~~~~~~
 
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 5beaf5f..caee08f 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -701,5 +701,9 @@ in MySQL. This exercises that case.
 >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, is_public=True)
 >>> ManagedModel.objects.update(data='mm')
 
+Sub-select using in lookup with Query object.
+>>> Author.objects.filter(extra__in=ExtraInfo.objects.filter(note__misc='foo').values('pk').query)
+[<Author: a1>, <Author: a2>]
+
 """}
 
-- 
1.5.3.7

