Skip to content

Commit

Permalink
improve pagination (added total key)
Browse files Browse the repository at this point in the history
  • Loading branch information
d2avids committed Aug 14, 2024
1 parent 4f14529 commit 69bd8b9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion backend/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.response import Response


class Limit100OffsetPagination(LimitOffsetPagination):
max_limit = 100

def paginate_queryset(self, queryset, request, view=None):
self.total_count = queryset.count()

return super().paginate_queryset(queryset, request, view)

def get_paginated_response(self, data):
return Response({
'total': self.total_count,
'count': len(data),
'limit': self.limit,
'offset': self.offset,
'results': data
})

0 comments on commit 69bd8b9

Please sign in to comment.