from rest_framework.pagination import CursorPagination, PageNumberPagination class VendorProductCursorPagination(CursorPagination): page_size = 20 ordering = '-created_at' cursor_query_param = 'cursor' class VendorProductPagePagination(PageNumberPagination): page_size = 20 page_size_query_param = 'page_size' max_page_size = 100 def get_paginated_response(self, data): from rest_framework.response import Response return Response({ "total_items": self.page.paginator.count, "total_pages": self.page.paginator.num_pages, "page_size": self.get_page_size(self.request), "current_page": self.page.number, "links": { "next": self.get_next_link(), "previous": self.get_previous_link(), }, "results": data, })