-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathpagination.py
31 lines (27 loc) · 895 Bytes
/
pagination.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from rest_framework.views import Response
from rest_framework.pagination import PageNumberPagination
from collections import OrderedDict
from django.conf import settings
class CustomizedPagination(PageNumberPagination):
"""
自定义分页器
"""
page_size = (
settings.REST_FRAMEWORK["PAGE_SIZE"]
if "PAGE_SIZE" in settings.REST_FRAMEWORK.keys()
else 20
)
page_query_param = "page"
page_size_query_param = "size"
max_page_size = None
def get_paginated_response(self, data):
return Response(
OrderedDict(
[
("count", data.get("count", self.page.paginator.count)),
("next", self.get_next_link()),
("previous", self.get_previous_link()),
("results", data.get("data", data)),
]
)
)