以下是我的模型,我正在使用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)
任何建议都将受到赞赏。