Django Filter with Pagination

前端 未结 6 1266
梦谈多话
梦谈多话 2020-12-19 12:47

I\'m attempting to follow the following tutorial for pagination with django filters, but the tutorial seems to be missing something, and i\'m unable to get the pagination to

6条回答
  •  春和景丽
    2020-12-19 13:17

    • Simple & sweet,
    • use this, pip install filter-and-pagination
    • https://pypi.org/project/filter-and-pagination/

    Implementation Step

    1. install package by pip install filter-and-pagination
    2. import FilterPagination by from filter_and_pagination import FilterPagination in view.py
    3. in your function writte code as bellow standards...
    queryset = FilterPagination.filter_and_pagination(request, Customer)
    serialize_data = CustomerSerializer(queryset['queryset'], many=True).data
    resultset = {'dataset': serialize_data, 'pagination': queryset['pagination']}
    
    • in this code Customer is Django model &
    • CustomerSerializer is a DRF Serializer class
    1. in the resultset it contains dataset & pagination data, In this format (API Response) link: https://github.com/ashish1997it/filter-pagination-dj#demo
    2. For the API request follow PostMan collection link: https://github.com/ashish1997it/filter-pagination-dj#postman in the header section it will take a parameter & request you customize as per your requirement

    If you still face any difficulty then contact me :)

提交回复
热议问题