30👍
✅
You can use skip
and limit
from QuerySet to achieve pagination.
For example if you want to show the second page with a limitation of 10 items per page, you can do like this:
page_nb = 2
items_per_page = 10
offset = (page_nb - 1) * items_per_page
list = Books.objects.skip( offset ).limit( items_per_page )
👤Eric
2👍
The flask-mongoengine plugin has an example of a paginator you could adapt to follow the digg paginator.
👤Ross
- Is it a good practice to use serializer as query parameters validators?
- Creating a MIME email template with images to send with python / django
- Confusion in Django admin, static and media files
1👍
You can use array-slicing syntax as well which is a bit more decent and readable :
begin = (page - 1) * page_size # offset
end = offset + page_size
list = Books.objects[begin:end]()
Source:stackexchange.com