Is this the *best* way to accomplish this? It seems like the author DB
query per book isn't very efficient (where it might sense to do a
JOIN) Also, if I was doing any more "levels" things would get very
complicated and bloated.

view.py:
...
def index(request):
        data = Book.objects.all().values('id','title',)
        books = []
        for b in data:
                book = Book.objects.all().get(id=b['id'])
                authors = book.authors.all().values('first_name','last_name',)
                books.append({
                        'id': b['id'],
                        'title':b['title'],
                        'authors':authors,
                })
        return render_to_response('books/index.html', {'books':books,})
...

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


--~--~---------~--~----~------------~-------~--~----~
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