{% if query%}
{%for book in results%}
{%for author in book.authors%}
{%endfor%}
{%endfor%}
{%else%}
{%endif%}
When I run it.I got an error message:
'ManyRelatedManager' object is not iterable.
the solution for this is
change the for loop syntax to:
{%for author in book.authors.all%}
then it'll be done.
20 comments:
You just made my day :)
Mine too.
The ManyRelatedManager object have a "all" method that returns the children array:
Example:
If you are defined a child list like this:
class myParent(models.Model):
aChildList = ManyToMany('myChildModel')
then, for read this list of child attribute do:
tmpChildList = myParent.aChildList.all()
for myChild in tmpChildList:
print myChild.name # if name is a field of the child
best regards!
thanks !
Saved me some time
Superhelpful. Thanks for posting.
thank you thank you thank you thank you thank you thank you thank you
Thanks! I was stuck on that!
Thank you so much!
I love when I use Google correctly. Thanks for giving me the exact answer I was looking for.
Great info. Please note that in the original post, all is used as a property. As Jean Machuca pointed out this is actually a method e.g. all()
thanks!
Thanks! This is the first result when Googling "manyrelatedmanager". Nice.
Thank you so much! :)
Thanks so mush! Saved som time!
Thanks!
Thank you dude !!!
So helpful for long time yet, thank you for sharing.
greetings from Brazil.
nice one - this saved me some time
Post a Comment