【发布时间】:2018-03-08 19:01:48
【问题描述】:
每当我使用cloth_image 创建Cloth 模型时,图像都会上传到upload_location。
我的问题是instance.id 返回None,因为该实例尚未创建。 ImageField 的最佳上传位置是什么?
def upload_location(instance, filename):
new_id = instance.id
ext = filename.split('.')[-1]
return "clothes/%s/%s.%s" % (instance.user.id, new_id, ext) # <- Right Here!
class Cloth(models.Model):
cloth_image = models.ImageField(upload_to=upload_location,
null=True,
blank=True)
我正在使用 AWS S3。
【问题讨论】:
标签: django django-models