119👍
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 can also see some tips here https://github.com/tomchristie/django-rest-framework/issues/1390
15👍
ModelViewSet or mixins.ListModelMixin automatically create pagination for us. You can stop it by
paginator = None
class NotesViewSet(viewsets.ModelViewSet):
queryset = Notes.objects.all()
serializer_class = NotesWriteSerializer
paginator = None
- [Django]-Sending post data from angularjs to django as JSON and not as raw content
- [Django]-OSError – Errno 13 Permission denied
- [Django]-How to go from django image field to PIL image and back?
5👍
And if you want paginator disabled for just one action:
@property
def paginator(self):
self._paginator = super(NotesViewSet, self).paginator
if self.action == 'the_action_you_want_pagination_disabled':
self._paginator = None
return self._paginator
use this in your ModelViewSet
.
- [Django]-How do you serialize a model instance in Django?
- [Django]-How to validate an Email address in Django?
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
3👍
In settings.py for global
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': None,
'PAGE_SIZE': 99999999, # a very large number
}
- [Django]-Manager isn't accessible via model instances
- [Django]-Can a dictionary be passed to django models on create?
- [Django]-Is there a way to undo a migration on Django and uncheck it from the list of showmigrations?
0👍
You can use a large number of items for specific view, keeping the results
attribute and default pagination number for all others views, using a custom Pagination Class like this:
from rest_framework import pagination, permissions, viewsets
class FooViewSet(viewsets.ReadOnlyModelViewSet):
class CustomFooPagination(pagination.PageNumberPagination):
page_size = 10000
pagination_class = CustomFooPagination
queryset = FooModel.objects.filter(enabled=True)
serializer_class = FooSerializer
permission_classes = [permissions.IsAuthenticated]
- [Django]-Django related_name for field clashes
- [Django]-How do I do an OR filter in a Django query?
- [Django]-Strange PostgreSQL "value too long for type character varying(500)"
0👍
It can be done via two way either one you like or choose for you
Paginator Property
class MyClassBasedView(ModelViewSet):
pagintor = None
Paginatior Class
class MyClassBasedView(ModelViewSet):
pagination_class = None
Details about why we use methods
Reason of using these ways because the ModelViewSet
class inherits GenericView
that inherits GenericAPIView
.
pagination class
is a property of GenericAPIView
that can be used to set pagination class or None for no pagination
paginator
is also a property of GenericAPIView
that can be used to set paginator class or None for no pagination
Reference: https://github.com/encode/django-rest-framework/blob/master/rest_framework/generics.py#L46
https://github.com/encode/django-rest-framework/blob/master/rest_framework/viewsets.py
- [Django]-Django Admin nested inline
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-Django admin: how to sort by one of the custom list_display fields that has no database field