Drop-in replacement for django admin default pagination that works fast with huge tables.
Low maintenance activity. Last release 13 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install django-admin-cursor-paginatordjango-admin-cursor-paginator
Drop-in replacement for django admin default pagination that works fast with huge tables.
Prerequisites
- You are using django (>2.0) admin
- Some of your models/tables contains so much data that list page lags
- You don't want to make separate CRM page for them and just need fast and simple solution
- You're ok that you won't see total objects or pages count and will navigate only by +-1 page
- Index must be created for the ordering field, otherwise you won't get any significant speedup (default integer pks work perfectly out-of-box)
- Ordering field type can be almost anything that can be "encoded" via
str()and then be used inqueryset.filter()
NOTE
If ordering field is not unique then pagination can mess a bit in edge cases. But for the most often case with datetime fields with milliseconds likecreated_atit won't be a problem. It can be solved in future by adding support for multiple ordering fields.
Installation
All you need is to install it via pip like that:
pip install django-admin-cursor-paginator
...and extend INSTALLED_APPS (it is needed only for templates):
INSTALLED_APPS = [
'django.contrib.admin',
# ...
'admin_cursor_paginator',
# ...
]
NOTE
This app overrides{% block pagination %}in defaultchange_list.htmlto insert custom pagination template tag, so if you use patchedchange_list.htmltoo, don't forget to copy pagination block or (seems better) to inherit this app tpl like{% extends 'admin_cursor_paginator/change_list.html' %}.Also, there's a known issue with grapelli that is fixed the same way.
Usage example
So this app will certainly help you if you're using admin to see some (usually) last inserted entries and may be also want to search for particular objects.
But anyways it's just a regular django admin page.
from admin_cursor_paginator import CursorPaginatorAdmin
class YourModelAdmin(CursorPaginatorAdmin):
cursor_ordering_field = '-created_at' # default is '-pk'
class AnotherModelAdmin(CursorPaginatorAdmin):
cursor_ordering_field = 'parent__sort' # joins are supported as well
