Vin*_*oft 1 python django django-models
在 Django 中,我有两个模型:
class A(models.Model):
# lots of fields
class B(models.Model):
a = models.ForeignKey(A)
member = models.BooleanField()
Run Code Online (Sandbox Code Playgroud)
我需要构建一个过滤 B 并选择所有 A 的查询,如下所示:
result = B.objects.filter(member=True).a
Run Code Online (Sandbox Code Playgroud)
上面的示例代码当然会返回错误 QuerySet has no attribute 'a'
预期结果:一个只包含 A 对象的 QuerySet
实现所需功能的最佳和最快方法是什么?