[英]Django-Admin custom ImageField
I wanna add additional ImageField
which obtains image from static
folder to the model.我想添加从
static
文件夹中获取图像的附加ImageField
到 model。 I've tried to use some answers from the same questions, but there aren't anything about ImageField
.我尝试使用相同问题的一些答案,但没有任何关于
ImageField
的内容。
def
def
加载图像的方法
# admin.py
@admin.register(Course)
class CourseAdmin(..., admin.ModelAdmin):
...
readonly_fields = [..., 'headshot_certic_preview_image', ]
fieldsets = (
... ,
('Image info', {
'fields': ('image', ('image_courses_and_course', 'image_dash'),
('certic_preview_image', 'first_row_course_name', 'second_row_course_name',
'headshot_certic_preview_image'),
),
}),
...
)
def headshot_certic_preview_image(self, obj):
return mark_safe('<img src="{url}" width="{width}" height={height} />'.format(
url=os.path.join('media/', obj.certic_preview_image.url),
width=700,
height=516
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.