【发布时间】:2018-09-22 00:04:41
【问题描述】:
我在这里找到了一个相关的问题: How can filter parent based on children in django
但是,我一直在努力寻找有特定孩子的父母。
使用与相关问题相同的模型:
class Kid(models.Model):
name = models.CharField(max_length=200)
class Toy(models.Model):
name = models.CharField(max_length=200)
material = models.CharField(max_length=200)
owner = models.ForeignKey(Kid)
如何找到拥有特定玩具的孩子?
Kid.objects.distinct().filter( ( toy__name='x' and toy__material='plastic')
and another ( toy__name='y' and toy__material='wood' )
and another ( toy__name='z' and toy__material='metal' )
and another .... )
【问题讨论】:
标签: django