My Django(1.6.2) project uses a 3rd party Django App installed on my virtualenv.
I need to setup a Django Signal to listen to post_save actions on a specific model(3rd party in virtualenv). I've tested the code bellow but it is not working.
I've placed the code in "views.py". I think this is the reason of the code not working.
from django.db.models.signals import post_save
from django.dispatch import receiver
from paypal.standard.models import PayPalStandardBase
@receiver(post_save, sender=PayPalStandardBase)
def my_handler(sender, **kwargs):
pdb.set_trace()
So, my question is. Where should I place this piece of code?
It doesn't matter at all where you put it. The only thing to bear in mind is that the code must actually be run, which means Django needs to import it at some point. If your views file contains some actual views that are referenced by urls and imported by urls.py, that would be fine. If not, put it somewhere that is imported.