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 """}