Issue
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
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
Answered By - willeM_ Van Onsem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.