Skip to content

Commit 030b444

Browse files
Eric Hurstmblayman
Eric Hurst
authored andcommitted
Use 'page_query_param' for pagination instead of hard coded page (#312)
* Use 'page_query_param' for pagination instead of hard coded page *** What - Use self.page_query_param to determine the query parameter to use for pagination - Set the default page_query_param to 'page' - Freeze fake-factory version to 0.7.4 *** Why - Allow the use of different page query parameters to do pagination - The latest version of fake-factory is now depreciated: https://pypi.python.org/pypi/fake-factory/9999.9.9 * Remove unneeded page_query_param default * Add documentation for default page_query_param
1 parent fbe49a1 commit 030b444

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

docs/usage.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ REST_FRAMEWORK = {
3131

3232
If `PAGE_SIZE` is set the renderer will return a `meta` object with
3333
record count and a `links` object with the next, previous, first, and last links.
34-
Pages can be selected with the `page` GET parameter. Page size can be controlled
35-
per request via the `PAGINATE_BY_PARAM` query parameter (`page_size` by default).
34+
Pages can be selected with the `page` GET parameter. The query parameter used to
35+
retrieve the page can be customized by subclassing `PageNumberPagination` and
36+
overriding the `page_query_param`. Page size can be controlled per request via
37+
the `PAGINATE_BY_PARAM` query parameter (`page_size` by default).
3638

3739
### Serializers
3840

rest_framework_json_api/pagination.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def build_link(self, index):
2020
if not index:
2121
return None
2222
url = self.request and self.request.build_absolute_uri() or ''
23-
return replace_query_param(url, 'page', index)
23+
return replace_query_param(url, self.page_query_param, index)
2424

2525
def get_paginated_response(self, data):
2626
next = None
@@ -75,10 +75,10 @@ def get_last_link(self):
7575
def get_first_link(self):
7676
if self.count == 0:
7777
return None
78-
78+
7979
url = self.request.build_absolute_uri()
8080
return remove_query_param(url, self.offset_query_param)
81-
81+
8282
def get_paginated_response(self, data):
8383
return Response({
8484
'results': data,
@@ -95,4 +95,4 @@ def get_paginated_response(self, data):
9595
('next', self.get_next_link()),
9696
('prev', self.get_previous_link())
9797
])
98-
})
98+
})

0 commit comments

Comments
 (0)