-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.py
More file actions
29 lines (21 loc) · 762 Bytes
/
pagination.py
File metadata and controls
29 lines (21 loc) · 762 Bytes
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
import rest_framework.pagination
import rest_framework.response
class CustomLimitOffsetPagination(
rest_framework.pagination.LimitOffsetPagination,
):
default_limit = 10
max_limit = 100
def get_limit(self, request):
param_limit = request.query_params.get(self.limit_query_param)
if param_limit is not None:
limit = int(param_limit)
if limit == 0:
return 0
if self.max_limit:
return min(limit, self.max_limit)
return limit
return self.default_limit
def get_paginated_response(self, data):
response = rest_framework.response.Response(data)
response.headers['X-Total-Count'] = str(self.count)
return response