[Fixed]-Calling a function in Django after saving a model

25👍

You can use signal dispatcher included in Django.

from django.db.models.signals import post_save
from django.dispatch import receiver

from myapp.models import Blog

@receiver(post_save, sender=Blog)
def my_handler(sender, **kwargs):
    print('post save callback')

See https://docs.djangoproject.com/en/stable/ref/signals/#post-save for more information.

3👍

Maybe you can use post_save signal in your app/model:

https://docs.djangoproject.com/en/1.10/ref/signals/#post-save

👤XaviP

Leave a comment