Reputation: 1648
I read the Django documentations about making my own signals but it is quiet difficult for me to grasp. Can you give me an example of making your own signal and give some details please? thank you in advance
Upvotes: 0
Views: 486
Reputation: 1069
You can create custom signal by defining
from django.dispatch import Signal
content_object_state_change = Signal(providing_args=["content_object", "created"])
Then you can send by it like below:
content_object_state_change.send(
sender=sender or obj.__class__, content_object=obj, created=True
)
And receive it as below. genrally this code can go to app.ready.py
function which get register when app initiate:
content_object_state_change.connect(content_object_state_change_receiver)
content_object_state_change_receiver
is a function with logic you would like to implement.
Upvotes: 1