From b7fa37f9b24a745c55c20e1767b98a647b25dadb Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 26 Feb 2007 04:53:44 +0000 Subject: [PATCH] Fixed #3170: added first_on_page and last_on_page arguments to paginated generic views. Thanks, Grimboy. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4591 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/generic/list_detail.py | 8 ++++++++ docs/generic_views.txt | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py index 1836ce4a9f..16d55202da 100644 --- a/django/views/generic/list_detail.py +++ b/django/views/generic/list_detail.py @@ -33,6 +33,12 @@ def object_list(request, queryset, paginate_by=None, page=None, number of pages, total hits number of objects, total + last_on_page + the result number of the last of object in the + object_list (1-indexed) + first_on_page + the result number of the first object in the + object_list (1-indexed) """ if extra_context is None: extra_context = {} queryset = queryset._clone() @@ -57,6 +63,8 @@ def object_list(request, queryset, paginate_by=None, page=None, 'page': page, 'next': page + 1, 'previous': page - 1, + 'last_on_page': paginator.last_on_page(page - 1), + 'first_on_page': paginator.first_on_page(page - 1), 'pages': paginator.pages, 'hits' : paginator.hits, }, context_processors) diff --git a/docs/generic_views.txt b/docs/generic_views.txt index 23f40acb24..3131fe7fe2 100644 --- a/docs/generic_views.txt +++ b/docs/generic_views.txt @@ -752,6 +752,12 @@ If the results are paginated, the context will contain these extra variables: * ``previous``: The previous page number, as an integer. This is 1-based. + * `last_on_page`: **New in Django development version** The number of the + last result on the current page. This is 1-based. + + * `first_on_page`: **New in Django development version** The number of the + first result on the current page. This is 1-based. + * ``pages``: The total number of pages, as an integer. * ``hits``: The total number of objects across *all* pages, not just this