将父母和孩子保存在数据库中
我有三张桌子。
class Parent():
pass
class Child():
parent = models.ForiegnKey(Parent)
class GrandChild():
child = models.ForiegnKey(Child)
现在父母可以有很多孩子,孩子有很多孙子,我的意思是100。
有什么方法可以同时保存父母/孩子/孙子?因此,我们只能获得 1 数据库命中,而父母/子/孙子都保存了。我知道Django中有可用的交易,但是根据我的理解(我可能是错误的)交易并不是解决此问题的解决方案。
I have Three tables.
class Parent():
pass
class Child():
parent = models.ForiegnKey(Parent)
class GrandChild():
child = models.ForiegnKey(Child)
Now Parent can have many Childs and child have many GrandChilds, i mean 100's.
Is there any way to save the Parent/Child/Grandchild at the same time ? So we get only 1 database hit and Parent/Child/Grandchild are all saved. I know there is transaction available in Django, but as per my understanding (I may be wrong) transactions are not the solution to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论