summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-23 13:49:07 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-23 13:49:07 +0000
commitabcb70e5245095628c4a00816138af9382e306fd (patch)
treeac3f8102d4d74d2524106b43e5602f1d8f2c0d5a
parent3940277792a33774bb17c622cdd753deb3ee17c6 (diff)
queryset-refactor: Added a convenience all() method to Querysets. Refs #3739
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6600 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/query.py7
-rw-r--r--docs/db-api.txt11
-rw-r--r--tests/regressiontests/queries/models.py5
3 files changed, 23 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 6a6fd82b18..cafec42697 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -246,6 +246,13 @@ class _QuerySet(object):
# PUBLIC METHODS THAT ALTER ATTRIBUTES AND RETURN A NEW QUERYSET #
##################################################################
+ def all(self):
+ """
+ Returns a new QuerySet that is a copy of the current one. This allows a
+ QuerySet to proxy for a model manager in some cases.
+ """
+ return self._clone()
+
def filter(self, *args, **kwargs):
"""
Returns a new QuerySet instance with the args ANDed to the existing
diff --git a/docs/db-api.txt b/docs/db-api.txt
index 6e121b8f3d..9fc82add4a 100644
--- a/docs/db-api.txt
+++ b/docs/db-api.txt
@@ -681,6 +681,17 @@ Examples::
>>> Entry.objects.none()
[]
+``all()``
+~~~~~~~~~~
+
+**New in Django development version**
+
+Returns a ''copy'' of the current ``QuerySet`` (or ``QuerySet`` subclass you
+pass in). This can be useful in some situations where you might want to pass
+in either a model manager or a ``QuerySet`` and do further filtering on the
+result. You can safely call ``all()`` on either object and then you'll
+definitely have a ``QuerySet`` to work with.
+
``select_related()``
~~~~~~~~~~~~~~~~~~~~
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index eb8595ecab..0a7ae286b7 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -374,5 +374,10 @@ upper bound.
>>> X.objects.select_related()
[]
+Bug #3739
+The all() method on querysets returns a copy of the queryset.
+>>> q1 = Item.objects.order_by('name')
+>>> id(q1) == id(q1.all())
+False
"""}