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)