Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between save and save_model()

Tags:

django

For all of my Django needs that overriding the save method requires, I've been using save() in my models. All the sudden when I was looking up something that required a little extra flare, someone suggested overriding save_model() in my admin class.

I found the docs on both, and I noticed right away that the arguments are different. Is save_model() only called when the model is saved from the admin? and the save() method is called whenever the model is saved?

UPDATE

So I've figured out that when saving from the admin. Both 'save' and 'save_model()' get called. It appears that 'save_model()' gets called first. In my specific application, I am using pre_save signals, and 'save()' overrides. Now I want to add in 'save_model()'overrides . It's the interaction and order of all of these save overrides and signals that is confusing me.

like image 423
Jglstewart Avatar asked Dec 20 '12 15:12

Jglstewart


1 Answers

As save() is a method of Model whereas save_model() is a method of ModelAdmin... yes.

like image 148
Ignacio Vazquez-Abrams Avatar answered Sep 19 '22 17:09

Ignacio Vazquez-Abrams