Skip to main content

Simple pagination for django

Project description

codecov version downloads license

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_universal_paginator-1.0.0.tar.gz (25.8 kB view hashes)

Uploaded Source

Built Distribution

django_universal_paginator-1.0.0-py3-none-any.whl (10.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page