#33095: Admin actions shown with zero results
-------------------------------------+-------------------------------------
Reporter: Richard Laager | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Comment (by Richard Laager):
I doubt this would get accepted into Django itself (as there would
probably be a concern about queryset edge cases), but for anyone finding
this bug... There is another way to eliminate the duplicate query in the
common case where no filters have been applied:
{{{
--- a/django/contrib/admin/views/main.py
+++ b/django/contrib/admin/views/main.py
@@ -280,7 +280,11 @@ class ChangeList:
# Get the total number of objects, with no admin filters applied.
if self.model_admin.show_full_result_count:
- full_result_count = self.root_queryset.count()
+ root_queryset = self.root_queryset
+ if root_queryset.query.where == self.queryset.query.where:
+ full_result_count = paginator.count
+ else:
+ full_result_count = root_queryset.count()
else:
full_result_count = None
can_show_all = result_count <= self.list_max_show_all
}}}
That checks to see if any conditions have been applied to the where
clause. If not, then there is no point in doing the root_queryset query,
as it will return the same thing that the paginator's count method will.
--
Ticket URL: <https://code.djangoproject.com/ticket/33095#comment:6>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070191fdc846c6-47e2ede5-a55c-474c-9b8c-ee15cc08e7ce-000000%40eu-central-1.amazonses.com.