我想对Django管理员进行一些自定义-尤其是changelist_view
class FeatureAdmin(admin.ModelAdmin):
list_display = (
'content_object_change_url',
'content_object',
'content_type',
'active',
'ordering',
'is_published',
)
list_editable = (
'active',
'ordering',
)
list_display_links = (
'content_object_change_url',
)
admin.site.register(get_model('features', 'feature'), FeatureAdmin)
这个想法是
'content_object_change_url'
可以是到另一个对象的change_view
的链接...方便管理员用户直接导航到该项目。我遇到这种情况的另一种情况是添加到外部源的链接或图像字段的缩略图。
我以为我听说过“插入HTML”选项-但也许我已经超越了我自己。
感谢您的帮助!
最佳答案
您可以在FeatureAdmin
类上提供一个自定义方法,该方法返回content_object_change_url
的HTML:
class FeatureAdmin(admin.ModelAdmin):
[...]
def content_object_change_url(self, obj):
return '<a href="%s">Click to change</a>' % obj.get_absolute_url()
content_object_change_url.allow_tags=True
参见the documentation。
关于django - Django管理员changelist_view中的自定义html字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3820182/