Skip to content

Paginator

NumberDetailPagination

Django Rest framework provides standard paginator classes but sometimes more details are needed to sent in the payload.

Payload definition

links': {
    'next': next page url,
    'previous': previous page url
    },
    'count': number of records fetched,
    'total_pages': total number of pages,
    'next': bool has next page,
    'previous': bool has previous page,
    'results': result set
})

How to use

  • View level:
from django_fast_utils.paginator import NumberDetailPagination
...

class MyView(ListAPIView):
    pagination_class = NumberDetailPagination
    ...
  • Making it global and default for all views with pagination:
REST_FRAMEWORK = {
    ...
    "DEFAULT_PAGINATION_CLASS": "django_fast_utils.paginator.NumberDetailPagination"
    ...
}