Ticket #6852: admin_pagination.diff

File admin_pagination.diff, 3.9 KB (added by nickefford, 7 years ago)

Fixes to pagination code of admin app

  • django/contrib/admin/templatetags/admin_list.py

     
    2222    elif i == cl.page_num:
    2323        return mark_safe(u'<span class="this-page">%d</span> ' % (i+1))
    2424    else:
    25         return mark_safe(u'<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1))
     25        return mark_safe(u'<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.num_pages-1 and ' class="end"' or ''), i+1))
    2626paginator_number = register.simple_tag(paginator_number)
    2727
    2828def pagination(cl):
     
    3737
    3838        # If there are 10 or fewer pages, display links to every page.
    3939        # Otherwise, do some fancy
    40         if paginator.pages <= 10:
    41             page_range = range(paginator.pages)
     40        if paginator.num_pages <= 10:
     41            page_range = range(paginator.num_pages)
    4242        else:
    4343            # Insert "smart" pagination links, so that there are always ON_ENDS
    4444            # links at either end of the list of pages, and there are always
     
    5050                page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1))
    5151            else:
    5252                page_range.extend(range(0, page_num + 1))
    53             if page_num < (paginator.pages - ON_EACH_SIDE - ON_ENDS - 1):
     53            if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1):
    5454                page_range.extend(range(page_num + 1, page_num + ON_EACH_SIDE + 1))
    5555                page_range.append(DOT)
    56                 page_range.extend(range(paginator.pages - ON_ENDS, paginator.pages))
     56                page_range.extend(range(paginator.num_pages - ON_ENDS, paginator.num_pages))
    5757            else:
    58                 page_range.extend(range(page_num + 1, paginator.pages))
     58                page_range.extend(range(page_num + 1, paginator.num_pages))
    5959
    6060    need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page
    6161    return {
  • django/contrib/admin/views/main.py

     
    55from django.views.decorators.cache import never_cache
    66from django.contrib.contenttypes.models import ContentType
    77from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
    8 from django.core.paginator import ObjectPaginator, InvalidPage
     8from django.core.paginator import QuerySetPaginator, InvalidPage
    99from django.shortcuts import get_object_or_404, render_to_response
    1010from django.db import models
    1111from django.db.models.query import handle_legacy_orderlist, QuerySet
     
    611611        return mark_safe('?' + '&amp;'.join([u'%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20'))
    612612
    613613    def get_results(self, request):
    614         paginator = ObjectPaginator(self.query_set, self.lookup_opts.admin.list_per_page)
     614        paginator = QuerySetPaginator(self.query_set, self.lookup_opts.admin.list_per_page)
    615615
    616616        # Get the number of objects, with admin filters applied.
    617617        try:
    618             result_count = paginator.hits
     618            result_count = paginator.count
    619619        # Naked except! Because we don't have any other way of validating
    620620        # "params". They might be invalid if the keyword arguments are
    621621        # incorrect, or if the values are not in the correct type (which would
     
    640640            result_list = list(self.query_set)
    641641        else:
    642642            try:
    643                 result_list = paginator.get_page(self.page_num)
     643                result_list = paginator.page(self.page_num+1).object_list
    644644            except InvalidPage:
    645645                result_list = ()
    646646
Back to Top