Ticket #1342: django_1342.diff

File django_1342.diff, 2.0 KB (added by Christopher Lenz <cmlenz@…>, 19 years ago)

Allow specifying the admin “results per page” per model

  • django/db/models/options.py

     
    196196class AdminOptions:
    197197    def __init__(self, fields=None, js=None, list_display=None, list_filter=None,
    198198        date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
    199         save_on_top=False, list_select_related=False, manager=None):
     199        save_on_top=False, list_select_related=False, manager=None, list_limit=None):
    200200        self.fields = fields
    201201        self.js = js or []
    202202        self.list_display = list_display or ['__str__']
    203203        self.list_filter = list_filter or []
     204        self.list_limit = list_limit
    204205        self.date_hierarchy = date_hierarchy
    205206        self.save_as, self.ordering = save_as, ordering
    206207        self.search_fields = search_fields or []
  • django/contrib/admin/views/main.py

     
    589589        return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
    590590
    591591    def get_results(self, request):
    592         paginator = ObjectPaginator(self.query_set, DEFAULT_RESULTS_PER_PAGE)
     592        results_per_page = self.lookup_opts.admin.list_limit
     593        if results_per_page is None:
     594            results_per_page = DEFAULT_RESULTS_PER_PAGE
     595        paginator = ObjectPaginator(self.query_set, results_per_page)
    593596
    594597        # Get the number of objects, with admin filters applied.
    595598        try:
     
    611614            full_result_count = self.manager.count()
    612615
    613616        can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
    614         multi_page = result_count > DEFAULT_RESULTS_PER_PAGE
     617        multi_page = result_count > results_per_page
    615618
    616619        # Get the list of objects to display on this page.
    617620        if (self.show_all and can_show_all) or not multi_page:
Back to Top