diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
index 027db63..ba35256 100644
a
|
b
|
def validate(cls, model):
|
46 | 46 | if hasattr(cls, 'list_display_links'): |
47 | 47 | check_isseq(cls, 'list_display_links', cls.list_display_links) |
48 | 48 | for idx, field in enumerate(cls.list_display_links): |
49 | | fetch_attr(cls, model, opts, 'list_display_links[%d]' % idx, field) |
50 | 49 | if field not in cls.list_display: |
51 | | raise ImproperlyConfigured("'%s.list_display_links[%d]'" |
| 50 | raise ImproperlyConfigured("'%s.list_display_links[%d]' " |
52 | 51 | "refers to '%s' which is not defined in 'list_display'." |
53 | 52 | % (cls.__name__, idx, field)) |
54 | 53 | |
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 32668e7..326cfcd 100644
a
|
b
|
subclass::
|
479 | 479 | By default, the change list page will link the first column -- the first |
480 | 480 | field specified in ``list_display`` -- to the change page for each item. |
481 | 481 | But ``list_display_links`` lets you change which columns are linked. Set |
482 | | ``list_display_links`` to a list or tuple of field names (in the same |
| 482 | ``list_display_links`` to a list or tuple of fields (in the same |
483 | 483 | format as ``list_display``) to link. |
484 | 484 | |
485 | | ``list_display_links`` can specify one or many field names. As long as the |
486 | | field names appear in ``list_display``, Django doesn't care how many (or |
| 485 | ``list_display_links`` can specify one or many fields. As long as the |
| 486 | fields appear in ``list_display``, Django doesn't care how many (or |
487 | 487 | how few) fields are linked. The only requirement is: If you want to use |
488 | 488 | ``list_display_links``, you must define ``list_display``. |
489 | 489 | |
diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py
index 20dfe2c..fda49d4 100644
a
|
b
|
class ValidationTestModel(models.Model):
|
31 | 31 | is_active = models.BooleanField() |
32 | 32 | pub_date = models.DateTimeField() |
33 | 33 | band = models.ForeignKey(Band) |
| 34 | |
| 35 | def decade_published_in(self): |
| 36 | return self.pub_date.strftime('%Y')[:3] + "0's" |
34 | 37 | |
35 | 38 | class ValidationTestInlineModel(models.Model): |
36 | 39 | parent = models.ForeignKey(ValidationTestModel) |
diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py
index 042c1b7..13c4151 100644
a
|
b
|
class ValidationTests(unittest.TestCase):
|
771 | 771 | ValidationTestModel, |
772 | 772 | ) |
773 | 773 | |
| 774 | def a_callable(obj): |
| 775 | pass |
| 776 | |
774 | 777 | class ValidationTestModelAdmin(ModelAdmin): |
775 | | list_display = ('name',) |
| 778 | def a_method(self, obj): |
| 779 | pass |
| 780 | list_display = ('name', 'decade_published_in', 'a_method', a_callable) |
776 | 781 | |
777 | 782 | validate(ValidationTestModelAdmin, ValidationTestModel) |
778 | | |
| 783 | |
779 | 784 | def test_list_display_links_validation(self): |
780 | 785 | |
781 | 786 | class ValidationTestModelAdmin(ModelAdmin): |
… |
… |
class ValidationTests(unittest.TestCase):
|
794 | 799 | |
795 | 800 | self.assertRaisesRegexp( |
796 | 801 | ImproperlyConfigured, |
797 | | "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' that is neither a field, method or property of model 'ValidationTestModel'.", |
| 802 | "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' which is not defined in 'list_display'.", |
798 | 803 | validate, |
799 | 804 | ValidationTestModelAdmin, |
800 | 805 | ValidationTestModel, |
… |
… |
class ValidationTests(unittest.TestCase):
|
805 | 810 | |
806 | 811 | self.assertRaisesRegexp( |
807 | 812 | ImproperlyConfigured, |
808 | | "'ValidationTestModelAdmin.list_display_links\[0\]'refers to 'name' which is not defined in 'list_display'.", |
| 813 | "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'name' which is not defined in 'list_display'.", |
809 | 814 | validate, |
810 | 815 | ValidationTestModelAdmin, |
811 | 816 | ValidationTestModel, |
812 | 817 | ) |
813 | 818 | |
| 819 | def a_callable(obj): |
| 820 | pass |
| 821 | |
814 | 822 | class ValidationTestModelAdmin(ModelAdmin): |
815 | | list_display = ('name',) |
816 | | list_display_links = ('name',) |
817 | | |
| 823 | def a_method(self, obj): |
| 824 | pass |
| 825 | list_display = ('name', 'decade_published_in', 'a_method', a_callable) |
| 826 | list_display_links = ('name', 'decade_published_in', 'a_method', a_callable) |
| 827 | |
818 | 828 | validate(ValidationTestModelAdmin, ValidationTestModel) |
819 | 829 | |
820 | 830 | def test_list_filter_validation(self): |