0

I used custom pagination as mentioned in Django rest framework. In that, I had to use my project name to give the path to CustomPagination, but every time it says module not found.

Then I manually import the pagination file in my views. It did work but my pagination links are appearing null. I have posted the picture here below.

enter image description here

My views:

from .pagination import CustomPagination

class ProductAPIView(ListAPIView):
    permission_classes = [AllowAny]
    queryset = Product.objects.all()
    serializer_class = ProductSerializer    
    filterset_class = ProductFilter
    pagination_class = CustomPagination

My pagination.py file

class CustomPagination(PageNumberPagination):
    def get_paginated_response(self, data):
        return Response({
            'links': {
                'next': self.get_next_link(),
                'previous': self.get_previous_link()
            },
            'count': self.page.paginator.count,
            'results': data
        })

My settings file:

 # 'DEFAULT_PAGINATION_CLASS': 'RupseOnline.core.pagination.CustomPagination',
    'PAGE_SIZE': 100,

I have commented out the pagination class and imported it manually in views because it says module not found.

Reactoo
  • 916
  • 2
  • 12
  • 40
  • 4
    If your page size (number of objects on the page) is 100 and in you example you only have 6 objects in total, there is no next or previous page. So previous and next are going to be null. If you would decrease the page size to less then the total amount of objects you have there should be a next page – Matt Feb 12 '21 at 06:51
  • Thanks Matt! It worked. I forgot to see that! – Reactoo Feb 12 '21 at 06:59

0 Answers0