我有模型:
class Model_1(models.Model):
name = models.CharField(...)
class Model_2(models.Model):
[...]
m1 = models.ManyToManyField(Model_1, blank=True, null=True)
class Model_3(models.Model):
[...]
m1 = models.ForeignKey(Model_1)
我想让所有 Model_3 对象变得简单。到目前为止,我是这样做的:
obj = Model_2.objects.filter(...)
this_i_want = []
for my2 in obj:
for my1 in my2.m1.all():
objects = Model_3.objects.filter(m1=my1)
for o in objects:
this_i_want.append(o)
怎么做最简单?我必须从 Model_2 出发。