Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Signal not triggering after save method is called

I have a signal set up to alert subscribers after the Food object has been updated. This helps to let them know if something changed about the food they are subscribed to. I have everything set up correctly according to the Django configuration but nothing happens after the Food object is updated. The Food object is in the models.py file of my meals app. I also added the meals app to INSTALLED_APPS.

# meals/signals.py

@receiver(post_save, sender=Food)
def alert_subscribers(created, instance, **kwargs):
    If not created:
        # My logic to alert subscribers

Thank you for your help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Adding it to the INSTALLED_APPS is not enough: Django does not trigger loading the signals module in an app, or at least not by itself.

You can load the signals, for example by the AppConfig:

# meals/apps.py

from django.apps import AppConfig


class MealsConfig(AppConfig):
    def ready(self):
        import meals.signals  # noqa
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading