Solution : Huge table retrieve in django-admin.

제공

In Django-admin, we can retrieve models.

It works well, if the records are small.

When it start to acculate over million records, it can be retrieved via django-admin (changelist view).

This is the very simple solution only for existing “id” and “id” is number.

 

[python]
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)



[/python]
from django.contrib import admin

class SomeModelAdmin(admin.ModelAdmin):
paginator = SimpleCountPaginator

But it is not perfect. Using this, I can retrieve narrow pages.
When I clicked last page, it stucked. 🙁
My conclusion is implementation for changelist view for huge table.
Not now, sadly.

AD

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다