{% 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.
You just made my day :)
ReplyDeleteMine too.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThe ManyRelatedManager object have a "all" method that returns the children array:
ReplyDeleteExample:
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 !
ReplyDeleteSaved me some time
Superhelpful. Thanks for posting.
ReplyDeletethank you thank you thank you thank you thank you thank you thank you
ReplyDeleteThanks! I was stuck on that!
ReplyDeleteThank you so much!
ReplyDeleteGreat 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()
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethanks!
ReplyDeleteThanks! This is the first result when Googling "manyrelatedmanager". Nice.
ReplyDeleteThank you so much! :)
ReplyDeleteThanks so mush! Saved som time!
ReplyDeleteThanks!
ReplyDeleteThank you dude !!!
ReplyDeleteSo helpful for long time yet, thank you for sharing.
ReplyDeletegreetings from Brazil.
nice one - this saved me some time
ReplyDelete