Turn off automatic pagination of the Django Rest Framework ModelViewSet

I am using the Django Rest Framework ModelViewSet for one of my views. ModelViewSet uses ListModelMixin , which automatically paginates the results, but I do not want the results to be paginated. In my API call, I say how many results I want to return, but since it costs, I cannot get more than 10 results in one call.

Is there a way to turn off automatic pagination, and so I can have as many results as I want to return?

+10
source share
3 answers

If you are using the latest versions of DRF, you just need to add pagination_class= None to the ModelViewSet definition.

 class MyClassBasedView(ModelViewSet): pagination_class = None ... 

You can also see some tips here https://github.com/tomchristie/django-rest-framework/issues/1390

+28
source

ModelViewSet or mixins.ListModelMixin automatically creates pagination for us. you can stop it paginator = None

 > class NotesViewSet(viewsets.ModelViewSet): > queryset = Notes.objects.all() > serializer_class = NotesWriteSerializer > paginator = None 
+2
source

For ListAPIView this worked for me

 class MyListAPIView(ListAPIView): page_size = 0 max_paginate_by = 0 ... 
0
source

All Articles