Django

Code

Changeset 7865

Show
Ignore:
Timestamp:
07/07/08 21:08:33 (2 months ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/admin/views/main.py

    r7491 r7865  
    66from django.contrib.contenttypes.models import ContentType 
    77from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied 
    8 from django.core.paginator import QuerySetPaginator, InvalidPage 
     8from django.core.paginator import Paginator, InvalidPage 
    99from django.shortcuts import get_object_or_404, render_to_response 
    1010from django.db import models 
  • django/trunk/django/core/paginator.py

    r7819 r7865  
    3737        "Returns the total number of objects, across all pages." 
    3838        if self._count is None: 
    39             self._count = len(self.object_list) 
     39            from django.db.models.query import QuerySet 
     40            if isinstance(self.object_list, QuerySet): 
     41                self._count = self.object_list.count() 
     42            else: 
     43                self._count = len(self.object_list) 
    4044        return self._count 
    4145    count = property(_get_count) 
     
    6266    page_range = property(_get_page_range) 
    6367 
    64 class QuerySetPaginator(Paginator): 
    65     """ 
    66     Like Paginator, but works on QuerySets. 
    67     """ 
    68     def _get_count(self): 
    69         if self._count is None: 
    70             self._count = self.object_list.count() 
    71         return self._count 
    72     count = property(_get_count) 
     68QuerySetPaginator = Paginator # For backwards-compatibility. 
    7369 
    7470class Page(object): 
  • django/trunk/django/views/generic/list_detail.py

    r7352 r7865  
    22from django.http import Http404, HttpResponse 
    33from django.core.xheaders import populate_xheaders 
    4 from django.core.paginator import QuerySetPaginator, InvalidPage 
     4from django.core.paginator import Paginator, InvalidPage 
    55from django.core.exceptions import ObjectDoesNotExist 
    66 
  • django/trunk/docs/pagination.txt

    r7311 r7865  
    6060    InvalidPage 
    6161 
     62Note that you can give ``Paginator`` a list/tuple or a Django ``QuerySet``. The 
     63only difference is in implementation; if you pass a ``QuerySet``, the 
     64``Paginator`` will call its ``count()`` method instead of using ``len()``, 
     65because the former is more efficient. 
     66 
    6267``Paginator`` objects 
    6368===================== 
     
    117122``paginator`` -- The associated ``Paginator`` object. 
    118123 
    119 ``QuerySetPaginator`` objects 
    120 ============================= 
    121  
    122 Use ``QuerySetPaginator`` instead of ``Paginator`` if you're paginating across 
    123 a ``QuerySet`` from Django's database API. This is slightly more efficient, and 
    124 there are no API differences between the two classes. 
    125  
    126124The legacy ``ObjectPaginator`` class 
    127125====================================