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.
精彩评论