Hi I am defining my own signal and receiver. I just want to know where I should place my codes. It is in models.py or in views.py. Please help
pre_save. This is sent at the beginning of a model's save() method. Arguments sent with this signal: sender.
Django Signals - post_delete()To notify another part of the application after the delete event of an object happens, you can use the post_delete signal.
In the example above, save_profile is our receiver function, User is the sender and post_save is the signal. You can read it as: Everytime when a User instance finalize the execution of its save method, the save_profile function will be executed. If you supress the sender argument like this: post_save.
Put your signal function into signals.py
and
don't forget to put the app config in the __init__.py
file and also
ready method in the apps.py
file.
apps.py
:
from django.apps import AppConfig
class AppNameConfig(AppConfig):
name = 'app_name'
def ready(self):
import app_name.signals
__init__.py
(app folder):
default_app_config = 'app_name.apps.AppNameConfig'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With