我有一个缩略图宽度因父对象(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