You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
987 B

from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination
from rest_framework.response import Response
class StandardResultsSetPagination(PageNumberPagination):
page_size = 16
page_size_query_param = 'page_size'
max_page_size = 100
def get_paginated_response(self, data):
return Response({
'count': self.page.paginator.count,
'next': self.get_next_link(),
'previous': self.get_previous_link(),
'results': data,
})
class NoPagination(PageNumberPagination):
def paginate_queryset(self, queryset, request, view=None):
self.count = len(queryset)
self.request = request
self.page = None
self.page_size = len(queryset)
return list(queryset)
def get_paginated_response(self, data):
return Response({
'count': self.count,
'next': None,
'previous': None,
'results': data,
})