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.
- Use the post_save signal
- Overwrite the save_model method in admin.py, since it is said in the documentation that "Overriding this method allows doing pre- or post-save operations."
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:
- For what I must do, what are the differences between the two approaches and what is the most correct.
- Is the save_model method related to the use of the admin interface? What happens if I use another frontend different from Django's admin?
- In general, what is the difference between doing pre and post save operations overwriting save_model and using signals?