diff options
| author | Tom Christie | 2012-11-09 05:07:34 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-11-09 05:07:34 -0800 |
| commit | c7df9694b5a7a7931161f74a7c5c16d5c98d87d9 (patch) | |
| tree | d2f832ad883a51ce2bde6b1d44b0156f300612c3 /rest_framework/pagination.py | |
| parent | 0089f0faa716bd37ca29f9f2db98b4ab273e01f1 (diff) | |
| parent | ff1234b711b8dfb7dc1cc539fa9d2b6fd2477825 (diff) | |
| download | django-rest-framework-c7df9694b5a7a7931161f74a7c5c16d5c98d87d9.tar.bz2 | |
Merge pull request #383 from tomchristie/filtering
Support for filtering backends
Diffstat (limited to 'rest_framework/pagination.py')
| -rw-r--r-- | rest_framework/pagination.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 131718fd..d241ade7 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -1,4 +1,5 @@ from rest_framework import serializers +from rest_framework.templatetags.rest_framework import replace_query_param # TODO: Support URLconf kwarg-style paging @@ -7,30 +8,30 @@ class NextPageField(serializers.Field): """ Field that returns a link to the next page in paginated results. """ + page_field = 'page' + def to_native(self, value): if not value.has_next(): return None page = value.next_page_number() request = self.context.get('request') - relative_url = '?page=%d' % page - if request: - return request.build_absolute_uri(relative_url) - return relative_url + url = request and request.build_absolute_uri() or '' + return replace_query_param(url, self.page_field, page) class PreviousPageField(serializers.Field): """ Field that returns a link to the previous page in paginated results. """ + page_field = 'page' + def to_native(self, value): if not value.has_previous(): return None page = value.previous_page_number() request = self.context.get('request') - relative_url = '?page=%d' % page - if request: - return request.build_absolute_uri('?page=%d' % page) - return relative_url + url = request and request.build_absolute_uri() or '' + return replace_query_param(url, self.page_field, page) class PaginationSerializerOptions(serializers.SerializerOptions): |
