[Django]-Pagination in django rest, ListAPIView

7👍

my_view.py

class BienAgence(generics.ListAPIView):
    queryset = FacebookBien.objects
    pagination_class = SmallPagesPagination

    def get(self, request, *args, **kwargs):
        ...
        serializer = FacebookBienSerializer(toto, many=True)
        page = self.paginate_queryset(serializer.data)
        return self.get_paginated_response(page)

-1👍

One way is to override the MyOffsetPagination class
like this

from rest_framework.pagination import LimitOffsetPagination

class MyOffsetPagination(LimitOffsetPagination):
    default_limit = 20
    max_limit = 1000

and then add this in your view

pagination_class = MyOffsetPagination

Don’t forget to add this in you settings

'DEFAULT_PAGINATION_CLASS': (
        'rest_framework.pagination.PageNumberPagination'),
    'PAGE_SIZE': (50)

Leave a comment