This is the documentation用于跟踪django中的关系
>>> b = Blog.objects.get(id=1)
>>> b.entry_set.all() # Returns all Entry objects related to Blog.
我想在列表中列出所有Blog对象和条目:
Blog1
<ul>
<li>Entry1 for Blog1</li>
<li>Entry2 for Blog1</li>
</ul>
Blog2
<ul>
<li>Entry1 for Blog2</li>
<li>Entry2 for Blog2</li>
</ul>
有没有办法做到这一点?像b = Blog.objects.all()
由于
答案 0 :(得分:0)
没有。您需要迭代Blog.objects.all()
并依次访问每个.entry_set.all()
。