drf default pagination
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 100
}
drf default pagination
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 100
}
how to use drf pagination directly
from rest_framework.views import APIView
from rest_framework.pagination import PageNumberPagination
class ProductList(APIView, PageNumberPagination):
# number of items per page by default
page_size = 1000
# max number of items per page
max_page_size = 1000
def get_queryset(self):
product_sync_ts = self.request.GET.get('product_sync_ts', None)
if product_sync_ts:
products = GrProduct.objects.filter(update_ts__gt=product_sync_ts)
return self.paginate_queryset(products)
raise APIException400(request, {'details': "Bad Request"})
def get(self, request):
products = self.get_queryset()
serializer = SyncedProductSerializer(instance={'products': products})
return self.get_paginated_response(serializer.data)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us