diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2016-02-29 11:12:25 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-01 08:20:14 -0500 |
| commit | 65bd053f11d22bca529f1da895599796fa0f3ee1 (patch) | |
| tree | 12605b392ed07b96420cf1f4cc49bc6a37e9925d /tests/modeladmin | |
| parent | 0223e213dd690b6b6e0669f836a20efb10998c83 (diff) | |
Fixed #26229 -- Improved check for model admin check admin.E124
Refs #22792
Diffstat (limited to 'tests/modeladmin')
| -rw-r--r-- | tests/modeladmin/tests.py | 49 |
1 files changed, 46 insertions, 3 deletions
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): |
