[Fixed]-Update model field and any other fields in django

1👍

Do you have several options.

First one is to overwrite save method on Backup model:

#Backup
def save(self, *args, **kwargs):
    if self.pk:
        previous_Backup = Backup.objects.get(self.pk).is_approve
    super(Backup, self).save(*args, **kwargs)
    if self.pk and self.is_approve != previous_Backup:
        #make changes

Second one is binding function to post save signal + django model utils field tracker:

@receiver(post_save, sender=Backup)
def create_change_backup(sender,instance, signal, created, **kwargs):
    if created:
        previous_Backup = get it from django model utils field tracker
        #make changes

Leave a comment