开发者

Populate Django Model Choice Field In __init__ or save?

开发者 https://www.devze.com 2023-03-14 08:22 出处:网络
I want t开发者_Python百科o set the choices for one of my fields based on the keyword arguments given to the model constructor. Does it make more sense to do this in the Model __init__ method or the sa

I want t开发者_Python百科o set the choices for one of my fields based on the keyword arguments given to the model constructor. Does it make more sense to do this in the Model __init__ method or the save() method?


That depends. Do you want it the dependent assignment to happen when you first create an instance of your model or do you want it to happen every time the model is saved? Putting it in an overridden save will give you a stronger guarantee that your dependent data won't get out of sync (so long as you don't use update() or drop down to raw SQL).

0

精彩评论

暂无评论...
验证码 换一张
取 消