ModelViewSets Pagination

GisangLee·2022년 8월 24일
0

my_module

목록 보기
32/33
post-custom-banner

기본 사용법

utils.paginations.py

from rest_framework.pagination import PageNumberPagination, CursorPagination


class BasePagination(PageNumberPagination):
    page_size = 3
    page_size_query_param = "page_size"
	

viewsets


class PageViewSet(...):
	...
    ...
    ...
    pagination_class = BasePagination
    
    ...
    def list(self, request):

        page = self.paginate_queryset(self.get_queryset())

        if page is not None:

            serializer = self.get_serializer(page, many=True)

            return self.get_paginated_response(serializer.data)
profile
포폴 및 이력서 : https://gisanglee.github.io/web-porfolio/
post-custom-banner

0개의 댓글