Created
December 6, 2019 09:36
-
-
Save kimjj81/91a54d6ce9c47f7b613bbc3b977a0cf3 to your computer and use it in GitHub Desktop.
Paginator for numerous records in Django-admin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.paginator import Paginator | |
class SimpleCountPaginator(Paginator): | |
def _get_count(self): | |
try: | |
first_id = self.object_list.first().id | |
last_id = self.object_list.last().id | |
if (first_id is None) or (last_id is None): | |
return 0 | |
max_id = max(last_id, first_id) | |
min_id = min(first_id, last_id) | |
result = max_id - min_id + 1 | |
return result | |
except Exception as e: | |
print(e) | |
return 0 | |
count = property(_get_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from django.contrib import admin
class SomeModelAdmin(admin.ModelAdmin):
paginator = SimpleCountPaginator