2 回答
TA贡献1818条经验 获得超7个赞
您不重复自己的解决方案是调用upload_design_to相关的Item
class Images(models.Model):
def upload_design_to(self, filename):
return self.item.upload_design_to(filename)
item = models.ForeignKey(Item, on_delete=models.CASCADE)
name = models.CharField(max_length=50, blank=True)
image = models.ImageField(blank=False, upload_to=upload_design_to)
TA贡献1735条经验 获得超5个赞
class Images(models.Model):
def upload_design_to(self, filename):
return f'{self.item.designer}/{self.item.title}/{filename}'
item = models.ForeignKey(Item, on_delete=models.CASCADE)
name = models.CharField(max_length=50, blank=True)
image = models.ImageField(blank=True, upload_to=upload_design_to)
def __str__(self):
return self.name
关于您提出的错误,您还可以为max_length文件字段设置一个属性,这样它就不会超过文件限制。您可以将其设置为 10000000 或足以容纳您的文件的长度。
添加回答
举报