diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 027db6383e..ba3525624d 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -46,9 +46,8 @@ def validate(cls, model): if hasattr(cls, 'list_display_links'): check_isseq(cls, 'list_display_links', cls.list_display_links) for idx, field in enumerate(cls.list_display_links): - fetch_attr(cls, model, opts, 'list_display_links[%d]' % idx, field) if field not in cls.list_display: - raise ImproperlyConfigured("'%s.list_display_links[%d]'" + raise ImproperlyConfigured("'%s.list_display_links[%d]' " "refers to '%s' which is not defined in 'list_display'." % (cls.__name__, idx, field)) diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 42c0a34055..c28dc8b7b3 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -479,11 +479,11 @@ subclass:: By default, the change list page will link the first column -- the first field specified in ``list_display`` -- to the change page for each item. But ``list_display_links`` lets you change which columns are linked. Set - ``list_display_links`` to a list or tuple of field names (in the same + ``list_display_links`` to a list or tuple of fields (in the same format as ``list_display``) to link. - ``list_display_links`` can specify one or many field names. As long as the - field names appear in ``list_display``, Django doesn't care how many (or + ``list_display_links`` can specify one or many fields. As long as the + fields appear in ``list_display``, Django doesn't care how many (or how few) fields are linked. The only requirement is: If you want to use ``list_display_links``, you must define ``list_display``. diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py index 20dfe2ce98..cb2e3d1b0b 100644 --- a/tests/regressiontests/modeladmin/models.py +++ b/tests/regressiontests/modeladmin/models.py @@ -8,7 +8,7 @@ class Band(models.Model): name = models.CharField(max_length=100) bio = models.TextField() sign_date = models.DateField() - + def __unicode__(self): return self.name @@ -32,5 +32,8 @@ class ValidationTestModel(models.Model): pub_date = models.DateTimeField() band = models.ForeignKey(Band) + def decade_published_in(self): + return self.pub_date.strftime('%Y')[:3] + "0's" + class ValidationTestInlineModel(models.Model): parent = models.ForeignKey(ValidationTestModel) diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py index 042c1b75ea..74dacd3227 100644 --- a/tests/regressiontests/modeladmin/tests.py +++ b/tests/regressiontests/modeladmin/tests.py @@ -771,8 +771,13 @@ class ValidationTests(unittest.TestCase): ValidationTestModel, ) + def a_callable(obj): + pass + class ValidationTestModelAdmin(ModelAdmin): - list_display = ('name',) + def a_method(self, obj): + pass + list_display = ('name', 'decade_published_in', 'a_method', a_callable) validate(ValidationTestModelAdmin, ValidationTestModel) @@ -794,7 +799,7 @@ class ValidationTests(unittest.TestCase): self.assertRaisesRegexp( ImproperlyConfigured, - "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' that is neither a field, method or property of model 'ValidationTestModel'.", + "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' which is not defined in 'list_display'.", validate, ValidationTestModelAdmin, ValidationTestModel, @@ -805,15 +810,20 @@ class ValidationTests(unittest.TestCase): self.assertRaisesRegexp( ImproperlyConfigured, - "'ValidationTestModelAdmin.list_display_links\[0\]'refers to 'name' which is not defined in 'list_display'.", + "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'name' which is not defined in 'list_display'.", validate, ValidationTestModelAdmin, ValidationTestModel, ) + def a_callable(obj): + pass + class ValidationTestModelAdmin(ModelAdmin): - list_display = ('name',) - list_display_links = ('name',) + def a_method(self, obj): + pass + list_display = ('name', 'decade_published_in', 'a_method', a_callable) + list_display_links = ('name', 'decade_published_in', 'a_method', a_callable) validate(ValidationTestModelAdmin, ValidationTestModel)