Solutions Log

So I only have to figure things out once.

Display Children of One-To-Many or Many-To-Many Relationships in Your Django Templates

For items you’ve defined in the parent model, such as this:

class Project(models.Model):
    tasks = models.ManyToManyField(Task, blank=True)

You use parent.children.all, like so:

For items defined outside of the parent model with a foreign key pointing back to the parent model, such as this:

class Picture(models.Model):
    project = models.ForeignKey(Project)

You use parent.children_set.all, like so:

Sources

Comments