How to limit query results with Django Rest filters

前端 未结 3 1981
南笙
南笙 2021-02-19 23:54

I am working on an api built with Django Rest Framework. I have defined several model classes and I have also created some filters to apply on certain

相关标签:
3条回答
  • 2021-02-20 00:07

    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.

    http://www.django-rest-framework.org/api-guide/pagination/

    0 讨论(0)
  • 2021-02-20 00:07

    you should use the pagination api from django-rest

    http://www.django-rest-framework.org/api-guide/pagination/

    look at the limit option

    0 讨论(0)
  • 2021-02-20 00:17

    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

    0 讨论(0)
提交回复
热议问题