Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有
Foo<=> FooGroup<=>Bar
Foo
FooGroup
Bar
关系,其中<=>代表 ManyToMany 字段。
<=>
如何检索Foo特定Bar实例的所有 s?
这是一个带有身份验证模型的示例,其中的关系非常类似于您的结构:用户 <=> 组 <=> 权限
from django.contrib.auth import models models.Permission.objects.filter(group__user=models.User.objects.get(username="webmaster"))
用你的例子:
Foo.objects.filter(foogroup__bar=barinstance)