因为我需要避免递归导入并将Group
对象作为查询的起点(这就是我不能Action
直接导入对象的原因。)
关系是Group
-> Component
-> ComponentVersion
->Action
例如,Group.components.all()
返回查询集中的所有组件。
另外[component.versions.all() for component in Group.components.all()]
返回一个查询集列表,其结果是所有版本。随后,.actions.all()
将返回理解中返回actions
的每个查询集的所有查询集ComponentVersion
。
避免对数据库进行不必要的调用和提高可读性的最佳方法是什么?