Author: adrian
Date: 2008-07-07 21:08:33 -0500 (Mon, 07 Jul 2008)
New Revision: 7865

Modified:
   django/trunk/django/contrib/admin/views/main.py
   django/trunk/django/core/paginator.py
   django/trunk/django/views/generic/list_detail.py
   django/trunk/docs/pagination.txt
Log:
Fixed #7478 -- Rolled QuerySetPaginator into the Paginator class, to simplify 
things. QuerySetPaginator still exists as an alias, for backwards 
compatibility. Thanks for the suggestion, [EMAIL PROTECTED]

Modified: django/trunk/django/contrib/admin/views/main.py
===================================================================
--- django/trunk/django/contrib/admin/views/main.py     2008-07-08 01:56:01 UTC 
(rev 7864)
+++ django/trunk/django/contrib/admin/views/main.py     2008-07-08 02:08:33 UTC 
(rev 7865)
@@ -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

Modified: django/trunk/django/core/paginator.py
===================================================================
--- django/trunk/django/core/paginator.py       2008-07-08 01:56:01 UTC (rev 
7864)
+++ django/trunk/django/core/paginator.py       2008-07-08 02:08:33 UTC (rev 
7865)
@@ -36,7 +36,11 @@
     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 @@
         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):

Modified: django/trunk/django/views/generic/list_detail.py
===================================================================
--- django/trunk/django/views/generic/list_detail.py    2008-07-08 01:56:01 UTC 
(rev 7864)
+++ django/trunk/django/views/generic/list_detail.py    2008-07-08 02:08:33 UTC 
(rev 7865)
@@ -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,

Modified: django/trunk/docs/pagination.txt
===================================================================
--- django/trunk/docs/pagination.txt    2008-07-08 01:56:01 UTC (rev 7864)
+++ django/trunk/docs/pagination.txt    2008-07-08 02:08:33 UTC (rev 7865)
@@ -59,6 +59,11 @@
     ...
     InvalidPage
 
+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 @@
 
 ``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
 ====================================
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to