#8408: Add a new meta option: don't do count(*) in admin
-------------------------------+-------------------------------------------
Reporter: LI Daobing | Owner: Thomas Chaumeny
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+-------------------------------------------
Comment (by Jerome Leclanche):
I've been using the following for a while:
{{{
#!python
class EstimatedCountPaginator(Paginator):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.object_list.count = self.count
@cached_property
def count(self):
if self.object_list.query.where:
return self.object_list.count()
db_table = self.object_list.model._meta.db_table
cursor = connections[self.object_list.db].cursor()
cursor.execute("SELECT reltuples FROM pg_class WHERE
relname = %s", (db_table, ))
result = cursor.fetchone()
if not result:
return 0
return int(result[0])
}}}
At the very least I believe such a paginator should be available by
default in `django.contrib.postgres`.
But going beyond that, the problem is that users are not always able to
modify the affected admin objects. So there should be some way of setting
the *default* paginator for all admin objects, I think.
--
Ticket URL: <https://code.djangoproject.com/ticket/8408#comment:49>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.d7cf01ba51d8dbdf29aa3f5ff8383d00%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.