-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination.py
28 lines (21 loc) · 1.12 KB
/
pagination.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
This module defines a custom pagination class for API responses.
Imports:
rest_framework.pagination: Provides utilities for pagination in Django REST Framework.
Classes:
CustomPageNumberPagination(PageNumberPagination):
A custom pagination class that extends Django REST Framework's PageNumberPagination class.
Attributes:
page_size (int): The default number of items to include on each page. Default is 1.
page_size_query_param (str): The query parameter name for specifying the page size. Default is 'limit'.
max_page_size (int): The maximum number of items allowed on a single page. Default is 2.
page_query_param (str): The query parameter name for specifying the page number. Default is 'p'.
Usage:
To use this custom pagination class in your Django REST Framework views, include it in the view configuration
'''
from rest_framework.pagination import PageNumberPagination
class CustomPageNumberPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'limit'
max_page_size = 10
page_query_param = 'p'