#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 michi88):

 What's wrong with just always calling `len(self.object_list)`?
 Using this saves me from the additional count of the filtered objects.
 This seems to work as the queryset is evaluated/fetched and cached on the
 `len(...)` call, after that another fetch is not needed to render the
 items in the admin list.
 {{{
 #!python
 class LenCountPaginator(Paginator):

     @cached_property
     def count(self):
         return len(self.object_list)
 }}}

 This is how de default Paginator does it:
 {{{
 #!python
 @cached_property
 def count(self):
     """
     Returns the total number of objects, across all pages.
     """
     try:
         return self.object_list.count()
     except (AttributeError, TypeError):
         # AttributeError if object_list has no count() method.
         # TypeError if object_list.count() requires arguments
         # (i.e. is of type list).
         return len(self.object_list)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/8408#comment:50>
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.fff6bf8a0389c5112330821cbf68b6b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to