mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
added paginated_response for functional views
This commit is contained in:
parent
4ff9e96b4c
commit
e981ddc654
|
@ -8,6 +8,7 @@ from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404 as _get_object_or_404
|
from django.shortcuts import get_object_or_404 as _get_object_or_404
|
||||||
|
|
||||||
from rest_framework import mixins, views
|
from rest_framework import mixins, views
|
||||||
|
from rest_framework.response import Response
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,3 +291,19 @@ class RetrieveUpdateDestroyAPIView(mixins.RetrieveModelMixin,
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
return self.destroy(request, *args, **kwargs)
|
return self.destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def paginated_response(request, queryset, serializer_class, pagination_class=None, **kwargs):
|
||||||
|
if pagination_class is None:
|
||||||
|
pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
|
||||||
|
|
||||||
|
paginator = pagination_class()
|
||||||
|
for attr, value in kwargs.items():
|
||||||
|
setattr(paginator, attr, value)
|
||||||
|
|
||||||
|
page = paginator.paginate_queryset(queryset, request)
|
||||||
|
if page is None:
|
||||||
|
serializer = serializer_class(queryset, many=True)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
serializer = serializer_class(page, many=True)
|
||||||
|
return paginator.get_paginated_response(serializer.data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user