Monday, July 14, 2008

'ManyRelatedManager' object is not iterable

When I'm writing an app ,in fact it's just a test.following is the actually code:
{% if query%}
{%for book in results%}

{{book.title}}


{%for author in book.authors%}
  • {{author.first_name}}|{{author.last_name}}

  • {%endfor%}

    {{book.publisher.name}}

    {%endfor%}
    {%else%}
  • No Books Found

  • {%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.