Can I manually trigger signals in Django?

Question:

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!

Asked By: david_hughes

||

Answers:

Yes. See the documentation:

from django.db.models.signals import post_save

instance = MyModel(field='qwerty')
post_save.send(MyModel, instance=instance, created=True)
Answered By: catavaran