Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@freakboy3742 freakboy3742 authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 tests/regressiontests/admin_changelist/tests.py
View
38 tests/regressiontests/admin_changelist/tests.py
@@ -113,11 +113,49 @@ def test_result_list_editable(self):
m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m))
+ def test_pagination(self):
+ """
+ Regression tests for #12893: Pagination in admins changelist doesn't
+ use queryset set by modeladmin.
+ """
+ parent = Parent.objects.create(name='anything')
+ for i in range(30):
+ Child.objects.create(name='name %s' % i, parent=parent)
+ Child.objects.create(name='filtered %s' % i, parent=parent)
+
+ request = MockRequest()
+
+ # Test default queryset
+ m = ChildAdmin(Child, admin.site)
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
+ m.list_select_related, m.list_per_page, m.list_editable, m)
+ self.assertEqual(cl.query_set.count(), 60)
+ self.assertEqual(cl.paginator.count, 60)
+ self.assertEqual(cl.paginator.page_range, [1, 2, 3, 4, 5, 6])
+
+ # Test custom queryset
+ m = FilteredChildAdmin(Child, admin.site)
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
+ m.list_select_related, m.list_per_page, m.list_editable, m)
+ self.assertEqual(cl.query_set.count(), 30)
+ self.assertEqual(cl.paginator.count, 30)
+ self.assertEqual(cl.paginator.page_range, [1, 2, 3])
+
class ChildAdmin(admin.ModelAdmin):
list_display = ['name', 'parent']
+ list_per_page = 10
def queryset(self, request):
return super(ChildAdmin, self).queryset(request).select_related("parent__name")
+class FilteredChildAdmin(admin.ModelAdmin):
+ list_display = ['name', 'parent']
+ list_per_page = 10
+ def queryset(self, request):
+ return super(FilteredChildAdmin, self).queryset(request).filter(
+ name__contains='filtered')
+
class MockRequest(object):
GET = {}
Please sign in to comment.
Something went wrong with that request. Please try again.