mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #14900 -- Added ability to override the paginator class used in a ModelAdmin. Thanks, Adam Vandenberg.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14997 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -9,6 +9,7 @@ from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_ob
|
||||
from django.contrib import messages
|
||||
from django.views.decorators.csrf import csrf_protect
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.core.paginator import Paginator
|
||||
from django.db import models, transaction, router
|
||||
from django.db.models.fields import BLANK_CHOICE_DASH
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
@@ -215,6 +216,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
date_hierarchy = None
|
||||
save_as = False
|
||||
save_on_top = False
|
||||
paginator = Paginator
|
||||
inlines = []
|
||||
|
||||
# Custom templates (designed to be over-ridden in subclasses)
|
||||
@@ -975,8 +977,9 @@ class ModelAdmin(BaseModelAdmin):
|
||||
|
||||
ChangeList = self.get_changelist(request)
|
||||
try:
|
||||
cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter,
|
||||
self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
|
||||
cl = ChangeList(request, self.model, list_display, self.list_display_links,
|
||||
self.list_filter, self.date_hierarchy, self.search_fields,
|
||||
self.list_select_related, self.list_per_page, self.list_editable, self.paginator, self)
|
||||
except IncorrectLookupParameters:
|
||||
# Wacky lookup parameters were given, so redirect to the main
|
||||
# changelist page, without parameters, and pass an 'invalid=1'
|
||||
|
||||
@@ -26,7 +26,7 @@ ERROR_FLAG = 'e'
|
||||
EMPTY_CHANGELIST_VALUE = '(None)'
|
||||
|
||||
class ChangeList(object):
|
||||
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_editable, model_admin):
|
||||
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_editable, paginator, model_admin):
|
||||
self.model = model
|
||||
self.opts = model._meta
|
||||
self.lookup_opts = self.opts
|
||||
@@ -40,6 +40,7 @@ class ChangeList(object):
|
||||
self.list_per_page = list_per_page
|
||||
self.list_editable = list_editable
|
||||
self.model_admin = model_admin
|
||||
self.paginator = paginator
|
||||
|
||||
# Get search parameters from the query string.
|
||||
try:
|
||||
@@ -94,7 +95,7 @@ class ChangeList(object):
|
||||
return '?%s' % urlencode(p)
|
||||
|
||||
def get_results(self, request):
|
||||
paginator = Paginator(self.query_set, self.list_per_page)
|
||||
paginator = self.get_paginator(self.query_set, self.list_per_page)
|
||||
# Get the number of objects, with admin filters applied.
|
||||
result_count = paginator.count
|
||||
|
||||
@@ -244,3 +245,6 @@ class ChangeList(object):
|
||||
|
||||
def url_for_result(self, result):
|
||||
return "%s/" % quote(getattr(result, self.pk_attname))
|
||||
|
||||
def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True):
|
||||
return self.paginator(queryset, per_page, orphans, allow_empty_first_page)
|
||||
|
||||
Reference in New Issue
Block a user