Django parent child model code example
Example 1: django models
Models in Django are classes that represent data base tables.
Example 2: how to get parent model object based on child model filter in django
#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')