@@ -34,14 +34,65 @@ REST_FRAMEWORK = {
34
34
}
35
35
```
36
36
37
- If ` PAGE_SIZE ` is set the renderer will return a ` meta ` object with
37
+ ### Pagination settings
38
+
39
+ If ` REST_FRAMEWORK['PAGE_SIZE'] ` is set the renderer will return a ` meta ` object with
38
40
record 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).
43
41
44
- #### Performance Testing
42
+ #### Subclassing paginators
43
+
44
+ The JSON API pagination classes can be subclassed to override settings as
45
+ described in the [ DRF pagination documentation] ( http://www.django-rest-framework.org/api-guide/pagination/ ) .
46
+
47
+ The default values are shown in these examples:
48
+
49
+ ``` python
50
+ from rest_framework_json_api.pagination import PageNumberPagination, LimitOffsetPagination
51
+
52
+ class MyPagePagination (PageNumberPagination ):
53
+ page_query_param = ' page'
54
+ page_size_query_param = ' page_size'
55
+ max_page_size = 100
56
+
57
+ class MyLimitPagination (LimitOffsetPagination ):
58
+ offset_query_param = ' page[offset]'
59
+ limit_query_param = ' page[limit]'
60
+ max_limit = None
61
+ ```
62
+
63
+ As shown above, pages can be selected with the ` page ` or ` page[limit] ` GET query parameter when using
64
+ the PageNumberPagination or LimitOffsetPagination class, respectively.
65
+
66
+ If you want to use the PageNumberPagination query parameter names shown
67
+ as an example in the JSON API [ specification] ( http://jsonapi.org/format/#fetching-pagination ) ,
68
+ set them as follows:
69
+ ``` python
70
+ class MyPagePagination (PageNumberPagination ):
71
+ page_query_param = ' page[number]'
72
+ page_size_query_param = ' page[size]'
73
+ ```
74
+
75
+ #### Setting global defaults for pagination
76
+
77
+ Set global defaults for the ` PageNumberPagination ` class with these settings:
78
+ - ` JSON_API_PAGE_NUMBER_PARAM ` sets the name of the page number query parameter (default: "page").
79
+ - ` JSON_API_PAGE_SIZE_PARAM ` sets the name of the page size query parameter (default: "page_size").
80
+ - ` JSON_API_MAX_PAGE_SIZE ` sets an upper limit for the page size query parameter (default: 100).
81
+
82
+ Set global defaults for the ` LimitOffsetPagination ` class with these settings:
83
+ - ` JSON_API_PAGE_OFFSET_PARAM ` sets the name of the page offset query parameter (default: "page\[ offset\] ").
84
+ - ` JSON_API_PAGE_LIMIT_PARAM ` sets the name of the page limit query parameter (default: "page\[ limit\] ").
85
+ - ` JSON_API_MAX_PAGE_LIMIT ` sets an upper limit for the page limit query parameter (default: None).
86
+
87
+ If you want to set the default PageNumberPagination query parameter names shown
88
+ as an example in the JSON API [ specification] ( http://jsonapi.org/format/#fetching-pagination ) ,
89
+ set them as follows:
90
+ ``` python
91
+ JSON_API_PAGE_NUMBER_PARAM = ' page[number]'
92
+ JSON_API_PAGE_SIZE_PARAM = ' page[size]'
93
+ ```
94
+
95
+ ### Performance Testing
45
96
46
97
If you are trying to see if your viewsets are configured properly to optimize performance,
47
98
it is preferable to use ` example.utils.BrowsableAPIRendererWithoutForms ` instead of the default ` BrowsableAPIRenderer `
@@ -606,6 +657,7 @@ with 1e18 rows which will likely exhaust any available memory and
606
657
slow your database to crawl.
607
658
608
659
The prefetch_related case will issue 4 queries, but they will be small and fast queries.
660
+
609
661
<!--
610
662
### Relationships
611
663
### Errors
0 commit comments