I think that anything that can be done with signal
also can be done by overriding save()
method in Model
.
If so, why do we need a signal? I can not find when to use the signal
.
Thanks
I think that anything that can be done with signal
also can be done by overriding save()
method in Model
.
If so, why do we need a signal? I can not find when to use the signal
.
Thanks
I think this may clarify your doubts :
About Django signals and override save method
Basically, people overrides save method to manipulate data from models before or after execute saving, signals are done precisely to cover the more possibilities of that scenario without alterations.
There are many situations when use of signal is essential. Since you are comparing with overiding save() method this example will give you one such scenario of use post_save signal. With post_save signal you can access the entire data stored in your database prior to the signal i.e. it will also provide you auto generated id of the data just stored by your database ( whether mysql, postgresql , mongodb etc. ). This can be used if you are saving two models with single save() function and want to link the two with same autogenerated pk.