0

我的模型结构如下。

class SuperModel(models.Model):
    field_1 = models.CharField(max_length=20)

class child_A(supermodel):
  class Meta:
     proxy = True

class child_B(supermodel):
  class Meta:
     proxy = True

class Reference(models.Model):
  child_a = models.ForeignKey(Child_A, blank=True, null=True)
  child_b = models.ForeignKey(Child_B, blank=True, null=True)
  super_model = models.ForeignKey(Child_C, related_name=supermodel)

我实际上有 4 个儿童模型。我已经展示了 2 来说明这一点。我一直在保留super_model ,这样我就可以在不检查所有孩子的情况下找到超级名模。只有一个孩子会参考超模。我Reference has more than One Foreign key to Child_B.在做runserver 的时候遇到错误,有人可以指出错误。

编辑:super_model 作为参考中的一个字段,我保留了这样我可以通过 SuperModel 的反向关系访问参考。

4

0 回答 0