Given a model with an ImageField and defined height/width fields, ex.
class Person(models.Model):
name = models.CharField(max_length=50)
mugshot = ImageField(storage=temp_storage, upload_to='tests',
height_field='mug_height', width_field='mug_width')
mug_height = models.PositiveSmallIntegerField()
mug_width = models.PositiveSmallIntegerField()
Dimensions fields aren't set if you do:
p = Person(name='Joe', mugshot=ImageFile(open(...)))
Actually, they are getting set when the ImageField gets the value assigned in Model.__init__() (using the ImageFileDescriptor), but since the height and width fields are defined after the ImageField, they get set back to None by Model.__init__().
After calling save on the instance:
p.save()
...the dimensions fields are set because save() ends up calling ImageFileDescriptor.__set__(), which updates the dimensions fields.
This is related to #10044, #10404, and #11084.