是否可以根据相关模型字段获取查询集。
伪代码:
#models.py
class Model1(models.Model):
a = models.CharField(max_length=50)
class Model2(models.Model):
model1 = models.ForeignKey(Model1)
# Get all model2 entries where model1.a == foo
答案 0 :(得分:2)
objects = Model2.objects.filter(model1__a='foo')