Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django pagination rest framework

from rest_framework.pagination import LimitOffsetPagination

class ProductsPagination(LimitOffsetPagination):
  default_limit = 10
  max_limit = 100

class EventNewsItems(APIView):

    def get(self, request, pk, format=None):
        event = Event.objects.get(pk=pk)
        news = event.get_news_items().all()
        
        pagination_class = ProductsPagination

        results = self.paginate_queryset(news, request, view=self)
        serializer = NewsItemSerializer(results, many=True)
        return self.get_paginated_response(serializer.data)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #django #pagination #rest #framework
ADD COMMENT
Topic
Name
6+3 =