All my sistem has pagination. I want request a single url without pagination, but as a request param, not in my remove in my application, because sometimes I want with pagination and sometimes without.
Anyone can help me?
CodePudding user response:
I did not get your question in 100%
But I think I can make you clear.
You can remove your pagination from your view if you do not using paginate_queryset method, specifically such classes as ModelViewSet or ReadOnlyViewSet, ListCreateAPIView, ListAPIView, ListModelMixin
You can use APIView or GenericAPIView and define get method and there put your logic without pagination
CodePudding user response:
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
if (queryset some condition): # here you can send data without paginate or in else it will automatically paginate the result
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
else:
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
