summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorHonza Král <Honza.Kral@gmail.com>2013-02-24 04:35:27 -0800
committerHonza Král <Honza.Kral@gmail.com>2013-02-24 04:35:27 -0800
commitd7e835f76d81d66a6d8964dba20506a1c6e559d8 (patch)
tree9a75ce90d4b6c8c4c5a33efcba0c39832783c531 /django
parenta44531ae1592cf266e6c24387f49d665c639b480 (diff)
parentf07a5f0a21857204465019b4e68f914d31cb396a (diff)
Merge pull request #820 from viciu/11295
Fixed #11295: If ModelAdmin.queryset returns a filtered QS don't require a 2nd count call
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/views/main.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index 4b296b3f4f..8bda323d83 100644
--- a/django/contrib/admin/views/main.py
+++ b/django/contrib/admin/views/main.py
@@ -79,15 +79,23 @@ class ChangeList(object):
self.title = title % force_text(self.opts.verbose_name)
self.pk_attname = self.lookup_opts.pk.attname
- def get_filters(self, request):
- lookup_params = self.params.copy() # a dictionary of the query string
- use_distinct = False
-
+ def get_filters_params(self, params=None):
+ """
+ Returns all params except IGNORED_PARAMS
+ """
+ if not params:
+ params = self.params
+ lookup_params = params.copy() # a dictionary of the query string
# Remove all the parameters that are globally and systematically
# ignored.
for ignored in IGNORED_PARAMS:
if ignored in lookup_params:
del lookup_params[ignored]
+ return lookup_params
+
+ def get_filters(self, request):
+ lookup_params = self.get_filters_params()
+ use_distinct = False
# Normalize the types of keys
for key, value in lookup_params.items():
@@ -166,14 +174,13 @@ class ChangeList(object):
result_count = paginator.count
# Get the total number of objects, with no admin filters applied.
- # Perform a slight optimization: Check to see whether any filters were
- # given. If not, use paginator.hits to calculate the number of objects,
- # because we've already done paginator.hits and the value is cached.
- if not self.query_set.query.where:
- full_result_count = result_count
- else:
+ # Perform a slight optimization:
+ # full_result_count is equal to paginator.count if no filters
+ # were applied
+ if self.get_filters_params():
full_result_count = self.root_query_set.count()
-
+ else:
+ full_result_count = result_count
can_show_all = result_count <= self.list_max_show_all
multi_page = result_count > self.list_per_page