[Django]-How can I iterate over ManyToManyField?

117👍

Try adding the () after all: myStuff.things.all()

👤Abid A

2👍

Like Abid A already answered, you are missing brackets ()

for t in myStuff.things.all():
    print t.myStuffs.all()

0👍

ManyToManyField seems to have a different kind of Manager than your basic Django class. Looking at the source here, https://github.com/django/django/blob/master/django/db/models/fields/related_descriptors.py#L821, it seems you are looking for the related_val field which appears to contain the tuple of related objects references.

👤jsh

Leave a comment