是否可以对给定的模型继承进行查询查找?

时间:2016-10-28 08:49:33

标签: python django django-models django-queryset

以下是我的模型,我正在使用InheritanceManager django-model-utils。我决定将字段user放在子类中,因为我需要通过Child之类的关系访问user.child1_set.all()子类。

class Mother(models.Model):
    objects = InheritanceManager()

class Child1(Mother):
    user = models.ForiegnKey(User)

class Child2(Mother):
    user = models.ForiegnKey(User)

问题是,当我想从Mother类开始查询时,似乎没有任何查询可以实现。

我试过这些代码。

Mother.objects.filter(user=SOMEUSER)
Mother.objects.filter(child1__user=SOMEUSER)
Mother.objects.select_subclasses().filder(user=SOMEUSER)
Mother.objects.select_subclasses().filder(child1__user=SOMEUSER)

任何建议都将受到赞赏。

0 个答案:

没有答案
相关问题