Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12893 -- Added tests to validate that the right queryset is al…

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15578 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit de161fbf21a77509d93804a66b28d2f28731e7e4 1 parent b3c7e39
Russell Keith-Magee authored February 19, 2011
38  tests/regressiontests/admin_changelist/tests.py
@@ -223,12 +223,50 @@ def test_distinct_for_m2m_to_inherited_in_list_filter(self):
223 223
         # There's only one ChordsBand instance
224 224
         self.assertEqual(cl.result_count, 1)
225 225
 
  226
+    def test_pagination(self):
  227
+        """
  228
+        Regression tests for #12893: Pagination in admins changelist doesn't
  229
+        use queryset set by modeladmin.
  230
+        """
  231
+        parent = Parent.objects.create(name='anything')
  232
+        for i in range(30):
  233
+            Child.objects.create(name='name %s' % i, parent=parent)
  234
+            Child.objects.create(name='filtered %s' % i, parent=parent)
  235
+
  236
+        request = MockRequest()
  237
+
  238
+        # Test default queryset
  239
+        m = ChildAdmin(Child, admin.site)
  240
+        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
  241
+                m.list_filter, m.date_hierarchy, m.search_fields,
  242
+                m.list_select_related, m.list_per_page, m.list_editable, m)
  243
+        self.assertEqual(cl.query_set.count(), 60)
  244
+        self.assertEqual(cl.paginator.count, 60)
  245
+        self.assertEqual(cl.paginator.page_range, [1, 2, 3, 4, 5, 6])
  246
+
  247
+        # Test custom queryset
  248
+        m = FilteredChildAdmin(Child, admin.site)
  249
+        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
  250
+                m.list_filter, m.date_hierarchy, m.search_fields,
  251
+                m.list_select_related, m.list_per_page, m.list_editable, m)
  252
+        self.assertEqual(cl.query_set.count(), 30)
  253
+        self.assertEqual(cl.paginator.count, 30)
  254
+        self.assertEqual(cl.paginator.page_range, [1, 2, 3])
  255
+
226 256
 
227 257
 class ChildAdmin(admin.ModelAdmin):
228 258
     list_display = ['name', 'parent']
  259
+    list_per_page = 10
229 260
     def queryset(self, request):
230 261
         return super(ChildAdmin, self).queryset(request).select_related("parent__name")
231 262
 
  263
+class FilteredChildAdmin(admin.ModelAdmin):
  264
+    list_display = ['name', 'parent']
  265
+    list_per_page = 10
  266
+    def queryset(self, request):
  267
+        return super(FilteredChildAdmin, self).queryset(request).filter(
  268
+            name__contains='filtered')
  269
+
232 270
 class MockRequest(object):
233 271
     GET = {}
234 272
 

0 notes on commit de161fb

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