答案 0 :(得分:3)
我通常这样做
from django.utils.html import linebreaks
class SomethingAdmin(admin.ModelAdmin):
list_display = [..., 'admin_get_variants']
def admin_get_variants(self, obj):
return linebreaks(obj.get_variants)
admin_get_variants.short_description = u'Get variants'
admin_get_variants.admin_ordering_field = 'get_variants'
admin_get_variants.allow_tags = True