Ticket #12893: test12893.patch

File test12893.patch, 1.8 KB (added by Matthias Kestenholz, 14 years ago)
  • tests/regressiontests/admin_changelist/tests.py

    diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
    index c8ad1ce..7c14d28 100644
    a b class ChangeListTests(TransactionTestCase):  
    7171        self.failIf('<td>%s</td>' % editable_name_field == -1,
    7272            'Failed to find "name" list_editable field in: %s' % table_output)
    7373
     74    def test_pagination_queryset(self):
     75        """
     76        Regression tests for #12893: Pagination in admins changelist doesn't
     77        use queryset set by modeladmin
     78        """
     79        parent = Parent.objects.create(name='anything')
     80        for i in range(200):
     81            Child.objects.create(name='name %s' % i, parent=parent)
     82            Child.objects.create(name='filtered %s' % i, parent=parent)
     83
     84        request = MockRequest()
     85        m = FilteredChildAdmin(Child, admin.site)
     86        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
     87                m.list_filter, m.date_hierarchy, m.search_fields,
     88                m.list_select_related, m.list_per_page, m.list_editable, m)
     89
     90        self.assertEqual(cl.query_set.count(), 200)
     91        self.assertEqual(cl.paginator.count, 200)
     92        self.assertEqual(cl.paginator.page_range, [1, 2])
     93
     94
    7495class ChildAdmin(admin.ModelAdmin):
    7596    list_display = ['name', 'parent']
    7697    def queryset(self, request):
    7798        return super(ChildAdmin, self).queryset(request).select_related("parent__name")
    7899
     100class FilteredChildAdmin(admin.ModelAdmin):
     101    list_display = ['name', 'parent']
     102    def queryset(self, request):
     103        return super(FilteredChildAdmin, self).queryset(request).filter(
     104            name__contains='filtered')
     105
    79106class MockRequest(object):
    80107    GET = {}
Back to Top