I'm writing a migration script and I don't want the signals to be triggered. How do I disconnect signal from views?
View.py
pre_save.disconnect( pre_save_callback, sender=MyModel)
Error:
NameError: name 'pre_save_callback' is not defined
signal handler:
@receiver(pre_save,sender=MyModel)
def pre_save_callback(sender, instance, *args, **kwargs):
'''
do some stuff
'''
print('running pre_save')
Fixed! Updated view code
The missing part was importing the signal handler function to the view and use it as the parameter in pre_save.disconnect().
At first, I thought that it will do an automatic look up of the function just by passing the function name as string. Hope this helps someone.
View.py
from app.signals.handler import pre_save_callback
pre_save.disconnect( pre_save_callback, sender=MyModel)