【发布时间】:2015-01-08 19:28:03
【问题描述】:
我想显示这样的图像Django admin listview Customize Column Name。 我检查了Django Admin Show Image from Imagefield、Django - Display ImageField、Django - How can I display a photo saved in ImageField?。
这是我的 models.py 和 admin.py。
#models.py
class Movie(models.Model):
id = models.IntegerField(primary_key=True)
master_id = models.IntegerField()
url = models.CharField(max_length=100)
cover = models.CharField(max_length=100)
tittle = models.CharField(max_length=50)
duration = models.CharField(max_length=10)
click = models.IntegerField()
platform_time = models.DateTimeField()
platform_type = models.IntegerField()
entry_date = models.DateTimeField()
enable = models.IntegerField()
def image_tag(self):
return u'<img src="%s" />' % self.cover
image_tag.short_description = 'Image'
image_tag.allow_tags = True
class Meta:
managed = False
db_table = 'movie'
#admin.py
class MovieAdmin(admin.ModelAdmin):
list_display = ('id', 'master_id', 'url', 'cover', 'tittle', 'duration', 'click', 'platform_time', 'platform_type', 'entry_date', 'enable')
search_fields = ('id', 'tittle',)
list_filter = ( 'enable', )
readonly_fields = ( 'image_tag', )
现在,这是我界面的一部分,没有 image_tag 字段。此外,如果我将封面字段修改为 image_tag,封面字段仍然不可见。
【问题讨论】: