Answer the question
In order to leave comments, you need to log in
Why is an error thrown when setting the width and height attributes on an ImageField model field?
In the model, I specify the following field:
image = models.ImageField(upload_to='photos', height_field=60, width_field=60, max_length=100)
Answer the question
In order to leave comments, you need to log in
Because these attributes do not set the width and height of the picture. They set the names of the fields in which djanga will write the actual width and height of the loaded image. Something like that:
class MyModel(models.Model):
img_width = models.PositiveIntegerField(null=True)
img_height = models.PositiveIntegerField(null=True)
image = models.ImageField(upload_to='photos', height_field='img_height', width_field='img_width', max_length=100)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question