Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off automatic pagination of Django Rest Framework ModelViewSet

I am using Django Rest Framework's ModelViewSet for one of my views. ModelViewSet uses the ListModelMixin which automatically paginates the results but I do not want the results paginated. In my API call I say how many results I want returned but as it stands I can't get back more than 10 results in one call.

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

like image 898
Bill Noble Avatar asked Apr 11 '16 15:04

Bill Noble


People also ask

How do I get rid of pagination in DRF?

If you are using recent versions of DRF you just need to add pagination_class = None to your ModelViewSet definition.

How does pagination work in Django REST framework?

Pagination is only performed automatically if you're using the generic views or viewsets. If you're using a regular APIView , you'll need to call into the pagination API yourself to ensure you return a paginated response. See the source code for the mixins. ListModelMixin and generics.

What is Restapi in Django?

Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs. Its main benefit is that it makes serialization much easier. Django REST framework is based on Django's class-based views, so it's an excellent option if you're familiar with Django.


1 Answers

If you are using recent versions of DRF you just need to add pagination_class = None to your ModelViewSet definition.

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

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

like image 141
trinchet Avatar answered Oct 18 '22 16:10

trinchet