11👍
✅
You can use Django Rest Framework pagination. The pagination_class LimitOffsetPagination
give you the ability to limit the number of returned entries in a query_param.
4👍
In ListApiView
Overwrite finalize_response
function. I did not find any other inbuilt method or parameter to set limit on response data.
from rest_framework.generics import ListAPIView
class BoolQSearch(ListAPIView):
queryset = Model1.objects.all()
serializer_class = Model1Serializer
def finalize_response(self, request, response, *args, **kwargs):
response.data = response.data[:5]
return super().finalize_response(request, response, *args, **kwargs)
3👍
You can extend or customize pagination classes available in drf
class UserSpecificPagination(LimitOffsetPagination):
def get_limit(self, request):
if logic_met(request.user):
self.max_limit = custom_limit
return super(UserSpecificPagination, self).get_limit(request)
set the class as pagination_class
in ListAPIView
or DRF settings
- Using ModelFormMixin without the 'fields' attribute is prohibited
- Django, REST and Angular Routes
- Testing a session variable
- Pass initial value to a modelform in django
- Provide tab title with reportlab generated pdf
1👍
you should use the pagination api from django-rest
http://www.django-rest-framework.org/api-guide/pagination/
look at the limit
option
👤Ward
- Updating context data in FormView form_valid method?
- From django.db import models, migrations ImportError: cannot import name migrations
- Proper declaration of an empty Django PostgreSQL JSONField default value in migration file
- Annotate django query if filtered row exists in second table
- Django Pandas to http response (download file)
Source:stackexchange.com