summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Christie <tom@tomchristie.com>2012-10-25 10:31:14 +0100
committerJannis Leidel <jannis@leidel.info>2012-11-17 21:30:22 +0100
commit2bfea3620842103d76972a17d77c3b75b4d30b86 (patch)
tree2058ed6e68fc7feacabbf957464906ba35496afa
parent94208399d958e0e9028d61d76f1b877eb3a8f74d (diff)
[1.5.x] Add 'page_kwarg' attribute to `MultipleObjectMixin`, removing hardcoded 'page'.
(cherry picked from commit 502be865c68635d5c31fa3fa58162b48412153ad)
-rw-r--r--django/views/generic/list.py4
-rw-r--r--docs/ref/class-based-views/mixins-multiple-object.txt11
2 files changed, 12 insertions, 3 deletions
diff --git a/django/views/generic/list.py b/django/views/generic/list.py
index e9d57a0702..b316c4bb56 100644
--- a/django/views/generic/list.py
+++ b/django/views/generic/list.py
@@ -17,6 +17,7 @@ class MultipleObjectMixin(ContextMixin):
paginate_by = None
context_object_name = None
paginator_class = Paginator
+ page_kwarg = 'page'
def get_queryset(self):
"""
@@ -39,7 +40,8 @@ class MultipleObjectMixin(ContextMixin):
Paginate the queryset, if needed.
"""
paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
- page = self.kwargs.get('page') or self.request.GET.get('page') or 1
+ page_kwarg = self.page_kwarg
+ page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1
try:
page_number = int(page)
except ValueError:
diff --git a/docs/ref/class-based-views/mixins-multiple-object.txt b/docs/ref/class-based-views/mixins-multiple-object.txt
index cdb743fcbd..e6abf26e6a 100644
--- a/docs/ref/class-based-views/mixins-multiple-object.txt
+++ b/docs/ref/class-based-views/mixins-multiple-object.txt
@@ -69,8 +69,15 @@ MultipleObjectMixin
An integer specifying how many objects should be displayed per page. If
this is given, the view will paginate objects with
:attr:`MultipleObjectMixin.paginate_by` objects per page. The view will
- expect either a ``page`` query string parameter (via ``GET``) or a
- ``page`` variable specified in the URLconf.
+ expect either a ``page`` query string parameter (via ``request.GET``)
+ or a ``page`` variable specified in the URLconf.
+
+ .. attribute:: page_kwarg
+
+ A string specifying the name to use for the page parameter.
+ The view will expect this prameter to be available either as a query
+ string parameter (via ``request.GET``) or as a kwarg variable specified
+ in the URLconf. Defaults to ``"page"``.
.. attribute:: paginator_class