mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Simplify NextPageField and PreviousPageField slightly
This commit is contained in:
parent
47b534a13e
commit
30799a3955
|
@ -4,14 +4,12 @@ from rest_framework.templatetags.rest_framework import replace_query_param
|
||||||
# TODO: Support URLconf kwarg-style paging
|
# TODO: Support URLconf kwarg-style paging
|
||||||
|
|
||||||
|
|
||||||
class PageField(serializers.Field):
|
class NextPageField(serializers.Field):
|
||||||
page_field = 'page'
|
|
||||||
|
|
||||||
|
|
||||||
class NextPageField(PageField):
|
|
||||||
"""
|
"""
|
||||||
Field that returns a link to the next page in paginated results.
|
Field that returns a link to the next page in paginated results.
|
||||||
"""
|
"""
|
||||||
|
page_field = 'page'
|
||||||
|
|
||||||
def to_native(self, value):
|
def to_native(self, value):
|
||||||
if not value.has_next():
|
if not value.has_next():
|
||||||
return None
|
return None
|
||||||
|
@ -21,10 +19,12 @@ class NextPageField(PageField):
|
||||||
return replace_query_param(url, self.page_field, page)
|
return replace_query_param(url, self.page_field, page)
|
||||||
|
|
||||||
|
|
||||||
class PreviousPageField(PageField):
|
class PreviousPageField(serializers.Field):
|
||||||
"""
|
"""
|
||||||
Field that returns a link to the previous page in paginated results.
|
Field that returns a link to the previous page in paginated results.
|
||||||
"""
|
"""
|
||||||
|
page_field = 'page'
|
||||||
|
|
||||||
def to_native(self, value):
|
def to_native(self, value):
|
||||||
if not value.has_previous():
|
if not value.has_previous():
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user