This is a library that provides custom pagination styles and pagination-related utilities for Django REST Framework.
VCS Branch | Deployment Environment | VCS Repository | CI/CD Status |
---|---|---|---|
develop |
Staging | GitHub | |
master |
Production | GitHub |
Code Coverage |
---|
Deployment Environment | Python Package Registry |
---|---|
Production | PyPI |
Install Python package:
pip install fyntex-drf-pagination-utils
from typing import Optional
import fyntex.drf_pagination_utils.styles
from rest_framework.settings import api_settings as drf_settings
class StandardResultSetPagination(
fyntex.drf_pagination_utils.styles.ObjectCountHeaderPageNumberPagination,
fyntex.drf_pagination_utils.styles.LinkHeaderPageNumberPagination,
):
"""
Custom pagination class used to override pagination settings from
:class:`rest_framework.pagination.PageNumberPagination`.
See also:
- https://www.django-rest-framework.org/api-guide/pagination/#configuration
- https://www.django-rest-framework.org/api-guide/pagination/#modifying-the-pagination-style
"""
page_size_query_param: Optional[str] = 'page_size'
"""
Name of the query parameter that allows the client to set the page size on a per-request basis.
"""
max_page_size: Optional[int] = drf_settings.PAGE_SIZE * 2 if drf_settings.PAGE_SIZE else None
"""
Maximum page size the client may request.
"""
object_count_header: Optional[str] = 'X-Pagination-Total-Item-Count'
Django settings:
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'example.StandardResultSetPagination',
}