Skip to main content

Keyset Pagination for Django.

Django pagination uses the LIMIT/OFFSET method. This is fine for smaller offsets, but once you start getting beyond a few pages, it can perform really badly. This is because the database needs to fetch all of the previous rows, even though it discards them.

Using Keyset Pagination allows for better performing "next page" fetches, at the cost of not being able to randomly fetch a page. That is, if you know the last element from page N-1, then you may fetch page N, but otherwise you really can't.

Keyset Pagination, sometimes called the Seek Method, has been documented by Markus Winand and Joe Nelson. If you are not familiar with the concept, I strongly suggest you read the articles above.

In order to use the paginator within this package, you will probably also need to use the provided View mixin: this changes the way a queryset is paginated to enable non-integer "page numbers".

class List(PaginationMixin, ListView):
    paginator_class = KeysetPaginator
    paginate_by = 10
    queryset = MyModel.objects.order_by('-timestamp', 'group')

You won't be able to iterate through page numbers in a template in the same way: you are limited to next and previous pages. Otherwise, you construct them in largely the same way:

<a href="{% url 'mymodel:list' %}?page={{ page_obj.previous_page_number }}">
  Prev Page
</a>

<a href="{% url 'mymodel:list' %}?page={{ page_obj.next_page_number }}">
  Next Page
</a>

Note that you do not get access to the length of the queryset, nor the number of pages, because these could be expensive queries. You really don't need to know that ;)

However, I like to use GET forms to enable pagination of filtered results:

<button form="target-form"
        name="page"
        value="{{ page_obj.previous_page_number }}"
        type="submit">
  &larr; Prev Page
</button>

<button form="target-form"
        name="page"
        value="{{ page_obj.next_page_number }}"
        type="submit">
  Next Page &rarr;
<button>

See https://schinckel.net/2018/11/23/keyset-pagination-in-django/ for more details about how this package works.

Download files

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

Source Distribution

django-keyset-pagination-plus-0.9.8.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_keyset_pagination_plus-0.9.8-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-keyset-pagination-plus-0.9.8.tar.gz.

File metadata

  • Download URL: django-keyset-pagination-plus-0.9.8.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for django-keyset-pagination-plus-0.9.8.tar.gz
Algorithm Hash digest
SHA256 e1476be0300f4a01563f189e1c8247a1d9b48dae666d5834a9c4077ca65e6688
MD5 b4b0713b63671530227fab237aaa7ab4
BLAKE2b-256 64bd62ca29d826816c62fda1776b7f1294d5c140942310676ce7b04313d9355e

See more details on using hashes here.

File details

Details for the file django_keyset_pagination_plus-0.9.8-py2.py3-none-any.whl.

File metadata

  • Download URL: django_keyset_pagination_plus-0.9.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for django_keyset_pagination_plus-0.9.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 96b5ea734eb8dad7401c59deb74aeb8d64bbb3dc53e09fad51d3a8abb88a06c2
MD5 aeeff0719f868ee64f7311cdcd969407
BLAKE2b-256 5fae9bb8a777db3b0015a913b5b95d922b97d37680b11f8ba50ca380c7a89547

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.9.10

1 file

0.9.9

2 files

This release

0.9.8 This release

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

1 file

0.9.0

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

1 file

0.8.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page