Reputation: 413
I am getting error IndexError: tuple index out of range while using CursorPagination of DRF. my code-
class CursorSetPagination(CursorPagination):
page_size = 10
page_size_query_param = 'page_size'
ordering = '-created_at'
class WalletCreditViewset(viewsets.ReadOnlyModelViewSet):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
pagination_class = CursorSetPagination
serializer_class = WalletCreditSerializer
def get_queryset(self):
queryset = PaymentOrder.objects.filter(user=self.request.user)
return queryset
The errors comes when the entry in the database table for a particular user cross the value of page_size.
Ex- if some user have 5 payment order then there will be no error but when the same user cross 10 payment order then this error occurs.
Upvotes: 1
Views: 125
Reputation: 29
I think you must order data in queryset, not in pagination.
for example:
class CursorSetPagination(CursorPagination):
page_size = 10
page_size_query_param = 'page_size'
class WalletCreditViewset(viewsets.ReadOnlyModelViewSet):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
pagination_class = CursorSetPagination
serializer_class = WalletCreditSerializer
def get_queryset(self):
queryset = PaymentOrder.objects.filter(user=self.request.user).order_by("-created_at")
return queryset
Upvotes: 0