I'm trying to use different sets of pagination classes on a viewset depending on query_params.
class BlockViewSet(viewsets.ModelViewSet):
pagination_class = defaultPaginationClass
def get_queryset(self):
queryset = Block.objects.all()
user = self.request.query_params.get('user', None)
if user is no None:
queryset = queryset.filter(user=user)
return queryset
so if the get request is made to /block/
, I want to use defaultPagination class while if the request is made to /block/?user=1
, I want to use customPagination class.
Try to redefine
paginator
property and if there is user query param, assign your custom pagination class toself._paginator
Final