Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #12893 -- Added tests to validate that the right querys…

…et is always used in model admins. Thanks to mk and Julien Phalip for their work on the patch.

Backport of r15578 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15579 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c9949103df95b34209e5187b27e92e5f9fd0aa32 1 parent efc4c62
Russell Keith-Magee authored February 19, 2011
38  tests/regressiontests/admin_changelist/tests.py
@@ -113,11 +113,49 @@ def test_result_list_editable(self):
113 113
                     m.list_filter, m.date_hierarchy, m.search_fields,
114 114
                     m.list_select_related, m.list_per_page, m.list_editable, m))
115 115
 
  116
+    def test_pagination(self):
  117
+        """
  118
+        Regression tests for #12893: Pagination in admins changelist doesn't
  119
+        use queryset set by modeladmin.
  120
+        """
  121
+        parent = Parent.objects.create(name='anything')
  122
+        for i in range(30):
  123
+            Child.objects.create(name='name %s' % i, parent=parent)
  124
+            Child.objects.create(name='filtered %s' % i, parent=parent)
  125
+
  126
+        request = MockRequest()
  127
+
  128
+        # Test default queryset
  129
+        m = ChildAdmin(Child, admin.site)
  130
+        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
  131
+                m.list_filter, m.date_hierarchy, m.search_fields,
  132
+                m.list_select_related, m.list_per_page, m.list_editable, m)
  133
+        self.assertEqual(cl.query_set.count(), 60)
  134
+        self.assertEqual(cl.paginator.count, 60)
  135
+        self.assertEqual(cl.paginator.page_range, [1, 2, 3, 4, 5, 6])
  136
+
  137
+        # Test custom queryset
  138
+        m = FilteredChildAdmin(Child, admin.site)
  139
+        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
  140
+                m.list_filter, m.date_hierarchy, m.search_fields,
  141
+                m.list_select_related, m.list_per_page, m.list_editable, m)
  142
+        self.assertEqual(cl.query_set.count(), 30)
  143
+        self.assertEqual(cl.paginator.count, 30)
  144
+        self.assertEqual(cl.paginator.page_range, [1, 2, 3])
  145
+
116 146
 
117 147
 class ChildAdmin(admin.ModelAdmin):
118 148
     list_display = ['name', 'parent']
  149
+    list_per_page = 10
119 150
     def queryset(self, request):
120 151
         return super(ChildAdmin, self).queryset(request).select_related("parent__name")
121 152
 
  153
+class FilteredChildAdmin(admin.ModelAdmin):
  154
+    list_display = ['name', 'parent']
  155
+    list_per_page = 10
  156
+    def queryset(self, request):
  157
+        return super(FilteredChildAdmin, self).queryset(request).filter(
  158
+            name__contains='filtered')
  159
+
122 160
 class MockRequest(object):
123 161
     GET = {}

0 notes on commit c994910

Please sign in to comment.
Something went wrong with that request. Please try again.