【发布时间】:2013-07-30 03:13:37
【问题描述】:
例如,我有一个模型 Cat,它与 Life 具有相反的 ForeignKey。
class Life(models.Model):
state = models.CharField(choices=('alive', 'dead', 'unknown')
cat = models.ForeignKey('animals.Cat', related_name="lives")
class Cat(models.Model):
name = models.CharField(max_length=12)
cat_type = models.CharField(choices=('normal', 'schroedinger')
...
我如何获得没有失去生命的Cats 中的QuerySet? IE。 所有他们的生命要么处于“活着”状态,要么属于 cat_type 'schroedinger',并且没有任何生命处于“死亡”状态)
【问题讨论】:
标签: python django django-queryset django-orm