Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I manually trigger signals in Django?

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!

like image 477
david_hughes Avatar asked Jan 16 '15 15:01

david_hughes


People also ask

Are Django signals asynchronous?

To answer directly: No. It's sync.

Where is Pre_save signal in Django?

pre_save. This is sent at the beginning of a model's save() method. Arguments sent with this signal: sender.

Should I use signals Django?

Only use signals to avoid introducing circular dependencies. If you have two apps, and one app wants to trigger behaviour in an app it already knows about, don't use signals. The app should just import the function it needs and call it directly.


1 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) 
like image 148
catavaran Avatar answered Sep 25 '22 08:09

catavaran