什麼時候用save什麼時候用signal

Always use the redefinition of the save-method, when ...

* you check given values
* you create directories or files (directly connected to the data model) e.g. I create a new directory for each new Memory
* you are auto-populating fields, like James Bennett explains.
* you do any action directly connected to the model you are operating on


Always use signals, when ...

* you want to report that something was added or changed
* you want to save new data-sets, which are associated to this model - e.g. when a new user is added to the system and you want to set the the default values of the website-settings (in case it is separated from User and UserProfile) - e.g. when a new user is added and you want to save a Welcome! Message into the internal Private Messaging system
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章