Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #7478 -- Rolled QuerySetPaginator into the Paginator class, to …

…simplify things. QuerySetPaginator still exists as an alias, for backwards compatibility. Thanks for the suggestion,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4406d283e13819b04556df21044089b7d119edb0 1 parent f19284b
@adrianholovaty adrianholovaty authored
2  django/contrib/admin/views/
@@ -5,7 +5,7 @@
from django.views.decorators.cache import never_cache
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
-from django.core.paginator import QuerySetPaginator, InvalidPage
+from django.core.paginator import Paginator, InvalidPage
from django.shortcuts import get_object_or_404, render_to_response
from django.db import models
from django.db.models.query import QuerySet
16 django/core/
@@ -36,7 +36,11 @@ def page(self, number):
def _get_count(self):
"Returns the total number of objects, across all pages."
if self._count is None:
- self._count = len(self.object_list)
+ from django.db.models.query import QuerySet
+ if isinstance(self.object_list, QuerySet):
+ self._count = self.object_list.count()
+ else:
+ self._count = len(self.object_list)
return self._count
count = property(_get_count)
@@ -61,15 +65,7 @@ def _get_page_range(self):
return range(1, self.num_pages + 1)
page_range = property(_get_page_range)
-class QuerySetPaginator(Paginator):
- """
- Like Paginator, but works on QuerySets.
- """
- def _get_count(self):
- if self._count is None:
- self._count = self.object_list.count()
- return self._count
- count = property(_get_count)
+QuerySetPaginator = Paginator # For backwards-compatibility.
class Page(object):
def __init__(self, object_list, number, paginator):
2  django/views/generic/
@@ -1,7 +1,7 @@
from django.template import loader, RequestContext
from django.http import Http404, HttpResponse
from django.core.xheaders import populate_xheaders
-from django.core.paginator import QuerySetPaginator, InvalidPage
+from django.core.paginator import Paginator, InvalidPage
from django.core.exceptions import ObjectDoesNotExist
def object_list(request, queryset, paginate_by=None, page=None,
12 docs/pagination.txt
@@ -59,6 +59,11 @@ page::
+Note that you can give ``Paginator`` a list/tuple or a Django ``QuerySet``. The
+only difference is in implementation; if you pass a ``QuerySet``, the
+``Paginator`` will call its ``count()`` method instead of using ``len()``,
+because the former is more efficient.
``Paginator`` objects
@@ -116,13 +121,6 @@ Attributes
``paginator`` -- The associated ``Paginator`` object.
-``QuerySetPaginator`` objects
-Use ``QuerySetPaginator`` instead of ``Paginator`` if you're paginating across
-a ``QuerySet`` from Django's database API. This is slightly more efficient, and
-there are no API differences between the two classes.
The legacy ``ObjectPaginator`` class

0 comments on commit 4406d28

Please sign in to comment.
Something went wrong with that request. Please try again.