I am using stdimage to auto resize my images, I have something like that :
class Image(models.Model):
image = stdimage.StdImageField(upload_to="images/uploads/", size=(width, height))
class Nevermind(models.Model):
w, h = 300, 150
image = models.ForeignKey(Image)
class Nevermind2(models.Model):
w, h = 100, 100
image = models.ForeignKey(Image)
So I would like pass width 开发者_开发百科and heigth as arguments to the Image class.
Thanks
I'm not sure exactly what your goal is, but you could try using model methods to define extra paramenters with the models.
#model
class Nevermind2(models.Model):
image = models.ForeignKey(image)
def size(self):
w,h = 100,100
return w, h
#example use
>>> a = Nevermind2.objects.get(pk=1)
>>> a.size()
(100,100)
>>> w,h = a.size()
>>> w
100
>>> h
100
精彩评论