I see I can override or define
pre_save, save, post_save
I shall try my best to explain it with an example:
save triggers the following steps
Django does provide a way to override these signals.
pre_save signal can be overridden for some processing before the actual save into the database happens - Example: (I dont know a good example of where
pre_save would be ideal at the top of my head)
Lets say you have a
ModelA which stores reference to all the objects of
ModelB which have not been edited yet. For this, you can register a
pre_save signal to notify
ModelA right before
save method gets called (Nothing stops you from registering a
post_save signal here too).
save method (it is not a signal) of the model is called - By default, every model has a
save method, but you can override it:
class ModelB(models.Model): def save(self): #do some custom processing here: Example: convert Image resolution to a normalized value super(ModelB, self).save()
Then, you can register the
post_save signal (This is more used that
A common usecase is
UserProfile object creation when
User object is created in the system.
You can register a
post_save signal which creates a
UserProfile object that corresponds to every
User in the system.
Signals are a way to keep things modular, and explicit. (Explicitly notify
ModelA if i
save or change something in
I shall think of more concrete realworld examples in an attempt to answer this question better. In the meanwhile, I hope this helps you