From 65bd053f11d22bca529f1da895599796fa0f3ee1 Mon Sep 17 00:00:00 2001 From: Alasdair Nicol Date: Mon, 29 Feb 2016 11:12:25 +0000 Subject: Fixed #26229 -- Improved check for model admin check admin.E124 Refs #22792 --- tests/modeladmin/tests.py | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'tests/modeladmin') diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 3e2dfe261b..c7e4b2c29d 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -1553,10 +1553,10 @@ class ListDisplayEditableTests(CheckTestCase): list_display_links = None self.assertIsValid(ProductAdmin, ValidationTestModel) - def test_list_display_same_as_list_editable(self): + def test_list_display_first_item_same_as_list_editable_first_item(self): """ - The first item in list_display can be the same as the first - in list_editable + The first item in list_display can be the same as the first in + list_editable. """ class ProductAdmin(ModelAdmin): list_display = ['name', 'slug', 'pub_date'] @@ -1564,6 +1564,49 @@ class ListDisplayEditableTests(CheckTestCase): list_display_links = ['pub_date'] self.assertIsValid(ProductAdmin, ValidationTestModel) + def test_list_display_first_item_in_list_editable(self): + """ + The first item in list_display can be in list_editable as long as + list_display_links is defined. + """ + class ProductAdmin(ModelAdmin): + list_display = ['name', 'slug', 'pub_date'] + list_editable = ['slug', 'name'] + list_display_links = ['pub_date'] + self.assertIsValid(ProductAdmin, ValidationTestModel) + + def test_list_display_first_item_same_as_list_editable_no_list_display_links(self): + """ + The first item in list_display cannot be the same as the first item + in list_editable if list_display_links is not defined. + """ + class ProductAdmin(ModelAdmin): + list_display = ['name'] + list_editable = ['name'] + self.assertIsInvalid( + ProductAdmin, ValidationTestModel, + "The value of 'list_editable[0]' refers to the first field " + "in 'list_display' ('name'), which cannot be used unless " + "'list_display_links' is set.", + id='admin.E124', + ) + + def test_list_display_first_item_in_list_editable_no_list_display_links(self): + """ + The first item in list_display cannot be in list_editable if + list_display_links isn't defined. + """ + class ProductAdmin(ModelAdmin): + list_display = ['name', 'slug', 'pub_date'] + list_editable = ['slug', 'name'] + self.assertIsInvalid( + ProductAdmin, ValidationTestModel, + "The value of 'list_editable[1]' refers to the first field " + "in 'list_display' ('name'), which cannot be used unless " + "'list_display_links' is set.", + id='admin.E124', + ) + class ModelAdminPermissionTests(SimpleTestCase): -- cgit v1.3