mirror of
https://github.com/django/django.git
synced 2025-10-27 15:46:10 +00:00
Fixed #7478 -- Rolled QuerySetPaginator into the Paginator class, to simplify things. QuerySetPaginator still exists as an alias, for backwards compatibility. Thanks for the suggestion, batiste@dosimple.ch
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7865 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -36,7 +36,11 @@ class Paginator(object):
|
||||
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 @@ class Paginator(object):
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user