📌  相关文章
📜  基于 django 分页类的视图 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:50.552000             🧑  作者: Mango

代码示例2
# stack overflow url: https://stackoverflow.com/questions/35830779/django-rest-framework-apiview-pagination

from rest_framework.pagination import LimitOffsetPagination

class EventNewsItems(APIView, LimitOffsetPagination):

    def get(self, request, pk, format=None):
        event = Event.objects.get(pk=pk)
        news = event.get_news_items().all()

        results = self.paginate_queryset(news, request, view=self)
        serializer = NewsItemSerializer(results, many=True)
        return self.get_paginated_response(serializer.data)