[Answer]-Updating two field from different models simultaneously

1๐Ÿ‘

โœ…

I would do a post_save signal function. So everytime you update Child Model it will trigger that function and you can change the Parent model:

from django.db.models.signals import post_save

# method for updating
def update_parent(sender, instance, **kwargs):
     parent = Parent.object.get() #the parent you need to update
     parent.modification_date = instance.modification_date
     parent.save()

# register the signal
post_save.connect(update_parent, sender=Child)
๐Ÿ‘คViroide

Leave a comment