📜  如何在 django 中基于子模型过滤器获取父模型对象 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:10.701000             🧑  作者: Mango

代码示例1
#Model
class Kid(models.Model):
    name = models.CharField(max_length=200)

class Toy(models.Model):
    name = models.CharField(max_length=200)
    owner = models.ForeignKey(Kid)
#view
Kid.objects.distinct().filter(toy__name__icontains='star')