Django 在管理页面上显示模型图像
Django show model images on Admin page
如何将属于该模型的图像添加到管理页面中该模型的详细信息页面?图片可以位于 data/text 的右侧或 data/text/
的下方
from django.db import models
# Create your models here.
class Gallery3(models.Model):
class Meta:
verbose_name = "Vintago Upload"
CATEGORIES = (
('Meubels', 'Meubels'),
('Vazen', 'Vazen'),
('Schilderijen', 'Schilderijen'),
)
title = models.CharField(max_length=100)
category = models.CharField(max_length=10, choices=CATEGORIES, default='Meubels')
description = models.CharField(max_length=255, blank=True)
document = models.ImageField(upload_to='images',null=True)
price= models.DecimalField(max_digits=10, decimal_places=2)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
#def get_absolute_url(self):
# return reverse('gallery_detail', kwargs={'pk': self.pk})
def image_img(self):
if self.image:
return marksafe('<img src="%s" />' % self.document)
else:
return '(no image)'
image_img.short_description = 'Thumb'
# and in your admin.py add:
list_display= ('image_img','product',)
readonly_fields = ('image_img',)
# and for adding it in the 'Edit mode' of your admin panel in your admin.py add:
fields = ( 'image_img', )
如何将属于该模型的图像添加到管理页面中该模型的详细信息页面?图片可以位于 data/text 的右侧或 data/text/
的下方from django.db import models
# Create your models here.
class Gallery3(models.Model):
class Meta:
verbose_name = "Vintago Upload"
CATEGORIES = (
('Meubels', 'Meubels'),
('Vazen', 'Vazen'),
('Schilderijen', 'Schilderijen'),
)
title = models.CharField(max_length=100)
category = models.CharField(max_length=10, choices=CATEGORIES, default='Meubels')
description = models.CharField(max_length=255, blank=True)
document = models.ImageField(upload_to='images',null=True)
price= models.DecimalField(max_digits=10, decimal_places=2)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
#def get_absolute_url(self):
# return reverse('gallery_detail', kwargs={'pk': self.pk})
def image_img(self):
if self.image:
return marksafe('<img src="%s" />' % self.document)
else:
return '(no image)'
image_img.short_description = 'Thumb'
# and in your admin.py add:
list_display= ('image_img','product',)
readonly_fields = ('image_img',)
# and for adding it in the 'Edit mode' of your admin panel in your admin.py add:
fields = ( 'image_img', )