本文介绍了Django用空的ManyToManyField选择对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑到以下模型,知道一个家庭,如何选择没有买家的孩子?
Considering the following models, knowing a family, how do I select Kids with no buyers?
class Family...
class Kid(models.Model):
name = models.CharField(max_length=255)
family = models.ForeignKey(Family)
buyer = models.ManyToManyField(Buyer, blank=True, null=True)
family = get_object_or_404(Family, pk=1)
for_sale = family.kid_set.filter(buyer... this screws my child trade business
推荐答案
family.kid_set .filter(buyer__isnull = True)
应该工作。
这篇关于Django用空的ManyToManyField选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!