notice/utils/pageination.py

29 lines
849 B
Python

# -*- coding: utf-8 -*-
# @Time : 2021/8/25 21:39
# @Author : Flora.Chen
# @File : pageination.py
# @Software: PyCharm
# @Desc:
from rest_framework.pagination import PageNumberPagination as _PageNumberPagination
class PageNumberPagination(_PageNumberPagination):
"""
"""
page_size = 10
page_query_param = 'page'
page_query_description = "指定获取的页码"
page_size_query_param = "size"
page_size_query_description = "指定每页的数据条数"
max_page_size = 100
def get_paginated_response(self, data):
response = super().get_paginated_response(data)
# 返回值中显示当前页码
response.data["current_page_num"] = self.page.number
# 返回值中显示总页数
response.data["total_pages"] = self.page.paginator.num_pages
return response