我有一個縮略圖寬度因父對象(ForeignKey)而異的模型。我需要能夠將這些信息提供給imagekit處理器。這是我的:django imagekit處理器:使用存儲在數據庫中的尺寸
class Wall(models.Model):
#...
width = models.SmallIntegerField(null=True, blank=True)
#...
class Poster(models.Model):
wall = models.ForeignKey(Wall, related_name='posters')
#...
original_image = models.ImageField(upload_to=upload_image_to)
def __init__(self, *args, **kwargs):
self.thumbnail = ImageSpecField([
Adjust(contrast=1.2, sharpness=1.1),
SmartResize(height=163, width=self.wall.width)
],
image_field='original_image', format='PNG'
)
super(Poster, self).__init__(*args, **kwargs)
#...
但是,如果我這樣做,沒有任何反應,甚至沒有生成縮略圖網址。
及以下將導致此此異常:
AttributeError的:「ForeignKey的」對象有沒有屬性「寬度」
class Poster(models.Model):
wall = models.ForeignKey(Wall, related_name='posters')
#...
original_image = models.ImageField(upload_to=upload_image_to)
thumbnail = ImageSpecField([
Adjust(contrast=1.2, sharpness=1.1),
SmartResize(height=163, width=wall.width)
],
image_field='original_image', format='PNG'
)
#...
認真嗎?沒有人想要賞金? – demux