how to get parent model object based on child model filter in django

Solutions on MaxInterview for how to get parent model object based on child model filter in django by the best coders in the world

showing results for - "how to get parent model object based on child model filter in django"
Angelo
10 Jun 2020
1#Model
2class Kid(models.Model):
3    name = models.CharField(max_length=200)
4
5class Toy(models.Model):
6    name = models.CharField(max_length=200)
7    owner = models.ForeignKey(Kid)
8#view
9Kid.objects.distinct().filter(toy__name__icontains='star')