Define a method in your ModelAdmin-class and set its allow_tags
attribute to True
. This will allow the method to return unescaped HTML for display in the column.
Then list it as an entry in the ModelAdmin.list_display attribute.
Example:
class YourModelAdmin(admin.ModelAdmin):
list_display = ('my_url_field',)
def my_url_field(self, obj):
return '<a href="%s%s">%s</a>' % ('http://url-to-prepend.com/', obj.url_field, obj.url_field)
my_url_field.allow_tags = True
my_url_field.short_description = 'Column description'
See the documentation for ModelAdmin.list_display for more details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…