How I can use pagination from list_route method? I have view:
class view(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
viewsets.GenericViewSet):
...
@list_route(methods=['get'])
def some_method(self, request, **kwargs):
queryset = Model.objects.all()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
You need to paginate your queryset
@list_route(methods=['get'])
def some_method(self, request, **kwargs):
queryset = Model.objects.all()
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)
Refer: http://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With