Can I manually trigger signals in Django?

david_hughes picture david_hughes · Jan 16, 2015 · Viewed 7k times · Source

I've written some signals in my Django app that are supposed to send out an email when a particular model instance is created or modified, but the signal receiver function doesn't seem to be responding; at any rate, I'm not getting any emails through (although I have already checked that I'm able to send emails with my current configuration).

Anyhow; I wondered, is it possible to manually send a post_save signal for debugging purposes, rather than trying to trigger it by creating a new model instance each time? Thanks!

Answer

catavaran picture catavaran · Jan 16, 2015

Yes. See the documentation:

from django.db.models.signals import post_save

instance = MyModel(field='qwerty')
post_save.send(MyModel, instance=instance, created=True)