Add 'page_kwarg' attribute to `MultipleObjectMixin`, removing hardcoded 'page'.
This commit is contained in:
parent
da56e1bac6
commit
502be865c6
|
@ -17,6 +17,7 @@ class MultipleObjectMixin(ContextMixin):
|
||||||
paginate_by = None
|
paginate_by = None
|
||||||
context_object_name = None
|
context_object_name = None
|
||||||
paginator_class = Paginator
|
paginator_class = Paginator
|
||||||
|
page_kwarg = 'page'
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
|
@ -39,7 +40,8 @@ class MultipleObjectMixin(ContextMixin):
|
||||||
Paginate the queryset, if needed.
|
Paginate the queryset, if needed.
|
||||||
"""
|
"""
|
||||||
paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
|
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:
|
try:
|
||||||
page_number = int(page)
|
page_number = int(page)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -69,8 +69,15 @@ MultipleObjectMixin
|
||||||
An integer specifying how many objects should be displayed per page. If
|
An integer specifying how many objects should be displayed per page. If
|
||||||
this is given, the view will paginate objects with
|
this is given, the view will paginate objects with
|
||||||
:attr:`MultipleObjectMixin.paginate_by` objects per page. The view will
|
:attr:`MultipleObjectMixin.paginate_by` objects per page. The view will
|
||||||
expect either a ``page`` query string parameter (via ``GET``) or a
|
expect either a ``page`` query string parameter (via ``request.GET``)
|
||||||
``page`` variable specified in the URLconf.
|
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
|
.. attribute:: paginator_class
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue