This commit is contained in:
Philip Neustrom 2015-02-04 14:37:18 +00:00
commit 57177f5fcd
3 changed files with 4 additions and 2 deletions

View File

@ -85,12 +85,13 @@ We could now use our pagination serializer in a view like this.
The generic class based views `ListAPIView` and `ListCreateAPIView` provide pagination of the returned querysets by default. You can customise this behaviour by altering the pagination style, by modifying the default number of results, by allowing clients to override the page size using a query parameter, or by turning pagination off completely. The generic class based views `ListAPIView` and `ListCreateAPIView` provide pagination of the returned querysets by default. You can customise this behaviour by altering the pagination style, by modifying the default number of results, by allowing clients to override the page size using a query parameter, or by turning pagination off completely.
The default pagination style may be set globally, using the `DEFAULT_PAGINATION_SERIALIZER_CLASS`, `PAGINATE_BY`, `PAGINATE_BY_PARAM`, and `MAX_PAGINATE_BY` settings. For example. The default pagination style may be set globally, using the `DEFAULT_PAGINATION_SERIALIZER_CLASS`, `PAGINATE_BY`, `PAGINATE_BY_PARAM`, `MAX_PAGINATE_BY`, and `PAGINATE_KWARG` settings. For example.
REST_FRAMEWORK = { REST_FRAMEWORK = {
'PAGINATE_BY': 10, # Default to 10 'PAGINATE_BY': 10, # Default to 10
'PAGINATE_BY_PARAM': 'page_size', # Allow client to override, using `?page_size=xxx`. 'PAGINATE_BY_PARAM': 'page_size', # Allow client to override, using `?page_size=xxx`.
'MAX_PAGINATE_BY': 100 # Maximum limit allowed when using `?page_size=xxx`. 'MAX_PAGINATE_BY': 100 # Maximum limit allowed when using `?page_size=xxx`.
'PAGINATE_KWARG': 'p' # Use `p` rather than `page` when paginating
} }
You can also set the pagination style on a per-view basis, using the `ListAPIView` generic class-based view. You can also set the pagination style on a per-view basis, using the `ListAPIView` generic class-based view.

View File

@ -60,7 +60,7 @@ class GenericAPIView(views.APIView):
paginate_by_param = api_settings.PAGINATE_BY_PARAM paginate_by_param = api_settings.PAGINATE_BY_PARAM
max_paginate_by = api_settings.MAX_PAGINATE_BY max_paginate_by = api_settings.MAX_PAGINATE_BY
pagination_serializer_class = api_settings.DEFAULT_PAGINATION_SERIALIZER_CLASS pagination_serializer_class = api_settings.DEFAULT_PAGINATION_SERIALIZER_CLASS
page_kwarg = 'page' page_kwarg = api_settings.PAGINATE_KWARG
# The filter backend classes to use for queryset filtering # The filter backend classes to use for queryset filtering
filter_backends = api_settings.DEFAULT_FILTER_BACKENDS filter_backends = api_settings.DEFAULT_FILTER_BACKENDS

View File

@ -61,6 +61,7 @@ DEFAULTS = {
# Pagination # Pagination
'PAGINATE_BY': None, 'PAGINATE_BY': None,
'PAGINATE_KWARG': 'page',
'PAGINATE_BY_PARAM': None, 'PAGINATE_BY_PARAM': None,
'MAX_PAGINATE_BY': None, 'MAX_PAGINATE_BY': None,