开发者

More efficient way to save multiple dependent objects in Django

One a single view, I have to create 3 objects which are dependent one from the other. My guess is that doing 3 database queries is extremely inefficient. Is there a better way of doing it?

character = char(user = request.user, race = form.clean_race())
character.save()

colony = colony(char = character)
colony.save开发者_开发百科()

buildings = colony_building(colony = colony, building_5 = 1)
buildings.save()

`


Assuming those are different models, you will need one SQL query per model, because SQL's INSERT can only target one table. So doing 3 queries for 3 models is OK to me.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜