from rest_framework.request import Request as DRFRequest
class HomeDataView(APIView):
def get(self, request, *args, **kwargs):
data = _inner_view(request)
...
def _inner_view(drf_request):
dr = DRFRequest(drf_request._request)
dr.query_params._mutable = True
dr.query_params['page_size'] = 5
dr.query_params['intellectualproperty'] = ip_id
vs = ProductViewSet(request=dr, action='list')
vs.initial(dr)
return vs.list(ds).data
# QuerySet を独自に作って処理したい場合
def _inner_view():
queryset = Schedule.objects.filter(...)
paginator = ScheduleViewSet.pagination_class()
page = paginator.paginate_queryset(queryset, self.request)
serializer = ScheduleViewSet.serializer_class(page, many=True)
response = paginator.get_paginated_response(serializer.data)
return response.data
コメント