Simple pagination for django
Project description
This package can render standard paginator and efficient cursor pagination.
Cursor pagination needs ordered queryset which can be used as unique key.
Install
pip install jango-universal-paginator
Usage
Settings
INSTALLED_APPS = (
# ...
'django_universal_paginator',
)
View
# views.py
class ObjectList(ListView):
paginate_by = 10
# model = ...
Template
<!-- object_list.html -->
{% load paginator_tags %}
<ul>
{% for object in object_list %}
<li>{{ object }}</li>
{% endfor %}
</ul>
<div class="pagination">{% pagination %}</div>
URLs
# urls.py
from django.urls import path, register_converter
from django_universal_paginator.converter import PageConverter, CursorPageConverter
register_converter(PageConverter, 'page')
register_converter(CursorPageConverter, 'cursor_page')
# standard
url(r'^object-list/<page:page>', ObjectList.as_view(), name='object_list'),
# or cursor
url(r'^cursor/<cursor_page:page>', ObjectList.as_view(), name='cursor_list'),
Cursor pagination
To enable cursor paginator just extend ListView using django_universal_paginator.CursorPaginateView and ensure, that queryset order_by can be used to uniquely index object.
class List(CursorPaginateView, ListView):
queryset = Book.objects.order_by('pk')
To use cursor pagination inside function based view, there is django_universal_paginator.paginate_cursor_queryset shortcut.
Paginator template
To override default paginator template create file paginator/paginator.html in directory with templates. Example paginator.html file is located in sample_project/templates/paginator directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_universal_paginator-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | edde465db2987185dc0021fdb64900fa336bf88ba8ff4d5c8e45e9a74279878b |
|
MD5 | 59f6af327680a2ba3c01ff970185ba40 |
|
BLAKE2b-256 | 2ee80ca48f0d0eb03d7ecfb2a406a522a39303bd44cca08fc1cf162079aadb05 |
Hashes for django_universal_paginator-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a4b1ec1b9e932b55355726dcd7c9a3df2dc15dc0d77115d071727a72f690f35 |
|
MD5 | 0a1523e0cac14dde8768c0bda17df5aa |
|
BLAKE2b-256 | 9374eecc5ea158cff5e7422edb77f1ada5f2b474f28d3a5b298a8c8a154f2c71 |