Let's say i need to call my own function def do_stuff()
after i save model. If that model would be in app which i have created, that would be no problem. I could do:
def save(self, *args, **kwargs):
super(Post, self).save(*args, **kwargs)
do_stuff()
But i need to call save()
in 3rd party app when model is saved. I can think of only copying all project to my local directory and append save()
method, but that is not nice since i have to copy all app code. Is there any nicer way to do this?
EDITED:
apps.py:
from django.apps import AppConfig
class SubscriptionConfig(AppConfig):
def ready(self):
import subscription.signals
signals.py:
from django.db.models.signals import post_save
from django.dispatch import receiver
from djangocms_blog.models import Post
@receiver(post_save, sender=Post)
def send_emails(instance, **kwargs):
print 'instance %s' %instance
__init__.py:
default_app_config = 'subscription.apps.SubscriptionConfig'