I have the following Django models:
class Image(TimeStamp):
hash = models.CharField(max_length=33,
unique=True,
editable=False)
filesize = models.PositiveIntegerField(blank=True,
null=True,
editable=False)
class Image1(Image):
image = models.ImageField(upload_to='image1/')
class Image2(Image):
image = models.ImageField(upload_to='image2/')
I want to be able to automatically compute filesize and hash upon image creation and the most reasonable place seems to me in a super class. However, I need to be able to access child class image field from the super class in order to compute hash and filesize. Is there a way to achieve this?
I added this save method to the superclass, but of course it doesn't know about image:
def save(self, *args, **kwargs):
super(Image, self).save(*args, **kwargs)
self.hash = hashlib.md5(self.image.read()).hexdigest()
self.filesize = self.image.size
upload_toin each child.