Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unistra/django-rest-framework-custom-paginations
Custom paginations for Django Rest Framework
https://github.com/unistra/django-rest-framework-custom-paginations
Last synced: 10 days ago
JSON representation
Custom paginations for Django Rest Framework
- Host: GitHub
- URL: https://github.com/unistra/django-rest-framework-custom-paginations
- Owner: unistra
- License: gpl-2.0
- Created: 2015-06-02T10:30:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-28T07:22:58.000Z (over 7 years ago)
- Last Synced: 2024-10-21T15:51:22.625Z (27 days ago)
- Language: Python
- Size: 13.7 KB
- Stars: 1
- Watchers: 21
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
django-rest-framework-custom-paginations
========================================Custom paginations for django rest framework
Compatibility
-------------work with :
* Python 2.7 / 3.4
* Dango 1.6 / 1.7
* Django Rest Framework 2.4 / 3.0 / 3.1 / 3.2 / 3.3Installation
------------Install the package from pypi: ::
pip install djangorestframework-custom-paginations
Add the application in your django settings: ::
DJANGO_APPS = ('rest_framework_custom_paginations',)
Configure your rest framework for DRF >= 3.1: ::
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework_custom_paginations.classes.SporePagination',
}or configure your rest framework for DRF < 3.1: ::
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_SERIALIZER_CLASS': 'rest_framework_custom_paginations.paginations.SporePaginationSerializer'
}Usage
-----Add the following parameters in a ListAPIView : ::
class PersonList(generics.ListAPIView):
""" list of person """
...
paginate_by = 100
paginate_by_param = 'page_size'
max_paginate_by = 500Example
-------Results of Spore Pagination : ::
{
"count": 532,
"next": "http://myurls/persons.json?structure=mystructure&page=3",
"next_params": {
"page": 3,
"structure": "mystructure"
},
"num_pages": 6,
"previous": "http://myurls/persons.json?structure=mystructure&page=1",
"previous_params": {
"page": 1,
"structure": "mystructure"
},
"results": [
...
]
}