summaryrefslogtreecommitdiff
path: root/tests/admin_changelist
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2013-09-06 15:25:13 -0300
committerTim Graham <timograham@gmail.com>2013-10-01 14:25:54 -0400
commit1d0fc61b1cadee584a27dbbe3ef3e21fd3202c85 (patch)
tree86a983c01d2bc888dd0511d3855b56a6a94c7ea6 /tests/admin_changelist
parentbf757a2f4dad519fac1b4a458376de3a040f5ca8 (diff)
downloaddjango-1d0fc61b1cadee584a27dbbe3ef3e21fd3202c85.tar.gz
Fixed #15185 -- Allowed ModelAdmin.list_display_links=None to disable change list links.
Thanks rm_ for the suggestion.
Diffstat (limited to 'tests/admin_changelist')
-rw-r--r--tests/admin_changelist/admin.py11
-rw-r--r--tests/admin_changelist/tests.py12
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index a63f2b60ce..b42f025b79 100644
--- a/tests/admin_changelist/admin.py
+++ b/tests/admin_changelist/admin.py
@@ -7,6 +7,7 @@ from .models import (Event, Child, Parent, Genre, Band, Musician, Group,
site = admin.AdminSite(name="admin")
+
class CustomPaginator(Paginator):
def __init__(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
super(CustomPaginator, self).__init__(queryset, 5, orphans=2,
@@ -80,6 +81,7 @@ class DynamicListDisplayChildAdmin(admin.ModelAdmin):
my_list_display.remove('parent')
return my_list_display
+
class DynamicListDisplayLinksChildAdmin(admin.ModelAdmin):
list_display = ('parent', 'name', 'age')
list_display_links = ['parent', 'name']
@@ -89,12 +91,20 @@ class DynamicListDisplayLinksChildAdmin(admin.ModelAdmin):
site.register(Child, DynamicListDisplayChildAdmin)
+
+class NoListDisplayLinksParentAdmin(admin.ModelAdmin):
+ list_display_links = None
+
+site.register(Parent, NoListDisplayLinksParentAdmin)
+
+
class SwallowAdmin(admin.ModelAdmin):
actions = None # prevent ['action_checkbox'] + list(list_display)
list_display = ('origin', 'load', 'speed')
site.register(Swallow, SwallowAdmin)
+
class DynamicListFilterChildAdmin(admin.ModelAdmin):
list_filter = ('parent', 'name', 'age')
@@ -105,6 +115,7 @@ class DynamicListFilterChildAdmin(admin.ModelAdmin):
my_list_filter.remove('parent')
return my_list_filter
+
class DynamicSearchFieldsChildAdmin(admin.ModelAdmin):
search_fields = ('name',)
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 2477edb55a..f9ef079904 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -19,7 +19,7 @@ from .admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,
DynamicListDisplayLinksChildAdmin, CustomPaginationAdmin,
FilteredChildAdmin, CustomPaginator, site as custom_site,
SwallowAdmin, DynamicListFilterChildAdmin, InvitationAdmin,
- DynamicSearchFieldsChildAdmin)
+ DynamicSearchFieldsChildAdmin, NoListDisplayLinksParentAdmin)
from .models import (Event, Child, Parent, Genre, Band, Musician, Group,
Quartet, Membership, ChordsMusician, ChordsBand, Invitation, Swallow,
UnorderedObject, OrderedObject, CustomIdUser)
@@ -460,6 +460,16 @@ class ChangeListTests(TestCase):
self.assertEqual(list_display, ('parent', 'name', 'age'))
self.assertEqual(list_display_links, ['age'])
+ def test_no_list_display_links(self):
+ """#15185 -- Allow no links from the 'change list' view grid."""
+ p = Parent.objects.create(name='parent')
+ m = NoListDisplayLinksParentAdmin(Parent, admin.site)
+ superuser = self._create_superuser('superuser')
+ request = self._mocked_authenticated_request('/parent/', superuser)
+ response = m.changelist_view(request)
+ link = reverse('admin:admin_changelist_parent_change', args=(p.pk,))
+ self.assertNotContains(response, '<a href="%s">' % link)
+
def test_tuple_list_display(self):
"""
Regression test for #17128