【发布时间】:2018-12-01 07:30:08
【问题描述】:
因为我需要避免递归导入并使用 Group 对象作为我查询的起点(这就是为什么我不能直接导入 Action 对象。)
关系是Group -> Component -> ComponentVersion -> Action
例如,Group.components.all() 返回查询集中的所有组件。
另外[component.versions.all() for component in Group.components.all()] 返回一个查询集列表,其结果是所有版本。随后,.actions.all() 将为理解中返回的每个 ComponentVersion 返回 actions 的所有查询集。
避免对数据库进行不必要的调用和提高可读性的最佳方法是什么?
【问题讨论】:
标签: django orm django-queryset django-related-manager