I've got this model in my Django app:
class Image(models.Model):
image_file = models.ImageField(
upload_to='images/',
width_field='width',
height_field='height'
)
width = models.PositiveIntegerField(
blank = True, null = True,
editable = False
)
height = models.PositiveIntegerField(
blank = True, null = True,
editable = False
)
sha1 = models.CharField(max_length=32, blank=True, editable=False)
filesize = models.PositiveIntegerField(blank=True, null=True, editable=False)
I can now upload images through the Django admin site. And the width
and height
properties are saved in the database automatically when it's uploaded, because of the special ImageField
parameters.
But I'd also like it to automatically work out the uploaded file's size and SHA-1 digest, and save those properties too. How would I do this?