在我的模型中,用户可以上传图片。对于那些我想存储缩略图的图像。 对于我正在尝试使用django-imagekit但我似乎没有让它工作的任务
class Imagen(models.Model):
def get_image_path(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join('uploads/images', str(instance.user.id), filename)
def get_thumb_image_path(instance, path, specname, extension):
path_thumb = re.sub("(\.\w+$)", "", path)
path_thumb = "%s%s%s" % (path_thumb, "_thumb", extension)
return path_thumb
user = models.ForeignKey(User)
imagen = models.ImageField(upload_to=get_image_path, format='JPEG')
imagen_thumb = ImageSpecField([ResizeToFill(92, 116)], image_field='imagen', cache_to=get_thumb_image_path, format='JPEG', options={'quality': 90})
insert_date = models.DateTimeField(auto_now_add=True, editable=False)
ImageSpecField用于保留原始文件并将新文件存储在cache_to(API)中,但它不起作用,
get_thumb_image_path以与get_image_path相同的路径响应,但在图像中添加了“_thumb”,如:
uploads/images/1/8836e0d5-8cce-4e3d-b3dc-35ec8ff451ce.jpg
uploads/images/1/8836e0d5-8cce-4e3d-b3dc-35ec8ff451ce_tumb.jpg