1👍
✅
def save(self, *args, **kwargs):
creating = self.pk is None
super(FileModel, self).save(*args, **kwargs)
if creating:
self.after_file = image_to_string(Image.open('base_file'), lang='en')
self.after_file.save()
or with signals:
from django.db.models import signals
from django.dispatch import receiver
@receiver(signals.post_save, sender=FileModel)
def create_file(sender, instance, created, *args, **kwargs):
if created:
instance.after_file = image_to_string(Image.open('base_file'), lang='en')
instance.after_file.save()
Source:stackexchange.com