开发者

Populate Django Model Choice Field In __init__ or save?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜