For my application I need to do extra operations when a model is saved via form. In practice, I need to add a value in another model if certain conditions are present in the form.
To do this I have two options, but I want to understand the pros and cons of both.
I currently use the latter in this way
def save_model(self, request, obj, form, change):
#some pre save operations....
#this call the save model method
super(MyModelAdmin, self).save_model(request, obj, form, change)
#some post save operations...
and it works
But what I want to understand is:
I think you got it right. And this might help you to understand the difference.
save_model
method from ModelAdmin
called when you are trying to create or update something from django admin only but signals are triggered regardless of place where actions happened. Which means pre
or post
operations in save_model
method won't work if you change model from somewhere outside of django admin but signals will work for both from outside of admin views and from your custom written code blocks.
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