mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #11058 - list_display_links doesn't allow callables not defined in the model
Thanks to dvine for the report and julien for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15619 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1b062f6613
commit
fdf9602961
4 changed files with 23 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue