@@ -15,7 +15,7 @@ REST_FRAMEWORK = {
1515 ' PAGE_SIZE' : 10 ,
1616 ' EXCEPTION_HANDLER' : ' rest_framework_json_api.exceptions.exception_handler' ,
1717 ' DEFAULT_PAGINATION_CLASS' :
18- ' rest_framework_json_api.pagination.PageNumberPagination ' ,
18+ ' rest_framework_json_api.pagination.JsonApiPageNumberPagination ' ,
1919 ' DEFAULT_PARSER_CLASSES' : (
2020 ' rest_framework_json_api.parsers.JSONParser' ,
2121 ' rest_framework.parsers.FormParser' ,
@@ -34,14 +34,55 @@ REST_FRAMEWORK = {
3434}
3535```
3636
37- If ` PAGE_SIZE ` is set the renderer will return a ` meta ` object with
37+ ### Pagination
38+
39+ DJA pagination is based on [ DRF pagination] ( http://www.django-rest-framework.org/api-guide/pagination/ ) .
40+
41+ When pagination is enabled, the renderer will return a ` meta ` object with
3842record count and a ` links ` object with the next, previous, first, and last links.
39- Pages can be selected with the ` page ` GET parameter. The query parameter used to
40- retrieve the page can be customized by subclassing ` PageNumberPagination ` and
41- overriding the ` page_query_param ` . Page size can be controlled per request via
42- the ` PAGINATE_BY_PARAM ` query parameter (` page_size ` by default).
4343
44- #### Performance Testing
44+ #### Configuring the Pagination Style
45+
46+ Pagination style can be set on a particular viewset with the ` pagination_class ` attribute or by default for all viewsets
47+ by setting ` REST_FRAMEWORK['DEFAULT_PAGINATION_CLASS'] ` and by setting ` REST_FRAMEWORK['PAGE_SIZE'] ` .
48+
49+ You can configure fixed values for the page size or limit -- or allow the client to choose the size or limit
50+ via query parameters.
51+
52+ Two pagination classes are available:
53+ - ` JsonApiPageNumberPagination ` breaks a response up into pages that start at a given page number with a given size
54+ (number of items per page). It can be configured with the following attributes:
55+ - ` page_query_param ` (default ` page[number] ` )
56+ - ` page_size_query_param ` (default ` page[size] ` ) Set this to ` None ` if you don't want to allow the client
57+ to specify the size.
58+ - ` max_page_size ` (default ` 100 ` ) enforces an upper bound on the ` page_size_query_param ` .
59+ Set it to ` None ` if you don't want to enforce an upper bound.
60+ - ` JsonApiLimitOffsetPagination ` breaks a response up into pages that start from an item's offset in the viewset for
61+ a given number of items (the limit).
62+ It can be configured with the following attributes:
63+ - ` offset_query_param ` (default ` page[offset] ` ).
64+ - ` limit_query_param ` (default ` page[limit] ` ).
65+ - ` max_limit ` (default ` 100 ` ) enforces an upper bound on the limit.
66+ Set it to ` None ` if you don't want to enforce an upper bound.
67+
68+
69+ These examples show how to configure the parameters to use non-standard names and different limits:
70+
71+ ``` python
72+ from rest_framework_json_api.pagination import JsonApiPageNumberPagination, JsonApiLimitOffsetPagination
73+
74+ class MyPagePagination (JsonApiPageNumberPagination ):
75+ page_query_param = ' page_number'
76+ page_size_query_param = ' page_size'
77+ max_page_size = 1000
78+
79+ class MyLimitPagination (JsonApiLimitOffsetPagination ):
80+ offset_query_param = ' offset'
81+ limit_query_param = ' limit'
82+ max_limit = None
83+ ```
84+
85+ ### Performance Testing
4586
4687If you are trying to see if your viewsets are configured properly to optimize performance,
4788it is preferable to use ` example.utils.BrowsableAPIRendererWithoutForms ` instead of the default ` BrowsableAPIRenderer `
0 commit comments