我想将图像src显示为Django Admin中的字段标记,我有:
class AImageAdmin(AdminFilteringFK, AdminListImageModel, admin.ModelAdmin):
model = AImage
list_display = ('image_tag', 'a', 'filename', 'file_type')
fields = ('a', 'image', 'image_tag', 'filename', 'file_type')
readonly_fields = ('filename', 'file_type', 'image_tag')
def image_tag(self, obj):
src = obj.image.url
return mark_safe(
'<img src="{url}" />'.format(url=src))
新字段是正确创建的,但由于某些原因(我不能让Django隐藏字段,添加&#34; display:none&#34;)
<img src="/media/a/28/image/at_2_zxkm.gif" style="display: none !important;" width="70;/">
答案 0 :(得分:0)
尝试:
def image_tag(self,
return '<img src="%s" />' % (obj.image.url)
image_tag.allow_tags = True
image_tag.short_description = 'Image'