I'm using the Books, Publishers, Authors example from the
documentation (Django Book) and I'm trying to figure out how to get
related data in a list. For example, I want to print a list of books
and a list of authors for each book in my template. What do I have to
do to make the code below function?

view.py
...
def index(request):
        books = Book.objects.all().select_related()[:3]
        return render_to_response('books/index.html', {'books':books,})
...

template.py
...
<ul>
{% for book in books %}
        <li><a href="/books/{{ book.id }}">{{ book.title }}</a>
        <ul>
        {% for author in book.authors %}
                <li>{{ author }}</li>
        {% endfor %}
        </ul>
        </li>
{% endfor %}
</ul>
...

Thanks in advance!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to