Ticket #11295: admin-count.2.diff

File admin-count.2.diff, 3.5 KB (added by Alex, 5 years ago)
  • django/contrib/admin/views/main.py

    diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
    index df0fd9f..7878873 100644
    a b class ChangeList(object): 
    104104
    105105        # Get the total number of objects, with no admin filters applied.
    106106        # Perform a slight optimization: Check to see whether any filters were
    107         # given. If not, use paginator.hits to calculate the number of objects,
    108         # because we've already done paginator.hits and the value is cached.
    109         if not self.query_set.query.where:
     107        # given by the user, if any came from ModelAdmin.queryset() we don't
     108        #consider them here. If not, use paginator.hits to calculate the number
     109        # of objects, because we've already done paginator.hits and the value
     110        # is cached.
     111        if not set(self.params) - set([ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR]):
    110112            full_result_count = result_count
    111113        else:
    112114            full_result_count = self.root_query_set.count()
    class ChangeList(object): 
    191193        # Naked except! Because we don't have any other way of validating "params".
    192194        # They might be invalid if the keyword arguments are incorrect, or if the
    193195        # values are not in the correct type, so we might get FieldError, ValueError,
    194         # ValicationError, or ? from a custom field that raises yet something else 
     196        # ValicationError, or ? from a custom field that raises yet something else
    195197        # when handed impossible data.
    196198        except:
    197199            raise IncorrectLookupParameters
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 0c7fbc0..8ceeb4d 100644
    a b  
    22
    33import re
    44import datetime
    5 from django.core.files import temp as tempfile
    6 from django.test import TestCase
    7 from django.contrib.auth.models import User, Permission
    8 from django.contrib.contenttypes.models import ContentType
     5
     6from django.conf import settings
     7from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
    98from django.contrib.admin.models import LogEntry, DELETION
    109from django.contrib.admin.sites import LOGIN_FORM_KEY
    1110from django.contrib.admin.util import quote
    12 from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
     11from django.contrib.auth.models import User, Permission
     12from django.contrib.contenttypes.models import ContentType
     13from django.core.files import temp as tempfile
     14from django.db import connection
     15from django.test import TestCase
    1316from django.utils import formats
    1417from django.utils.cache import get_max_age
    1518from django.utils.html import escape
    class AdminCustomQuerysetTest(TestCase): 
    12891292            else:
    12901293                self.assertNotContains(response, 'Primary key = %s' % i)
    12911294
     1295    def test_changelist_view_count_queries(self):
     1296        old_debug = settings.DEBUG
     1297        settings.DEBUG = True
     1298        num_queries = len(connection.queries)
     1299        response = self.client.get('/test_admin/admin/admin_views/emptymodel/')
     1300        # The page should do 5 queries: 1 for the session, 1 for the user, 1
     1301        # for the count, 1 for user messages, and 1 for the objects on the page
     1302        self.assertEqual(len(connection.queries), num_queries+5, len(connection.queries) - num_queries)
     1303
    12921304    def test_change_view(self):
    12931305        for i in self.pks:
    12941306            response = self.client.get('/test_admin/admin/admin_views/emptymodel/%s/' % i)
Back to Top