I'm sure this will be very easy for most of you...

I am trying to display a list.

in views.py, I have:

from mysite.books.models import Book
from django.http import HttpResponse

def book_list(request):
    book = Book.objects.all().order_by('title')
    return render_to_response('books/book_list.html', {'book': book})

in models.py, I have:

class Book(models.Model):
    title = models.CharField(maxlength=100)
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher)
    publication_date = models.DateField()
    num_pages = models.IntegerField(blank=True, null=True)

    def __str__(self):
        return self.title

In my HTML is:

<p>
{% if "book_list" %}
<p>There are books</p>
{% endif %}
</p>

<p>
The title of your books: {{ book }}
</p>


Now the thing is, when it renders in the browser, I get something that
looks like this:

There are books
The title of your books: [, ]


If I view source, I get this:

<p>There are books</p>
<p>The title of your books: [<Book: Book 1>, <Book: Book 2>]</p>

So clearly the data is there - I just can't see it. Can anyone help
shed light on this, please? I have been at it all day and I am am
about to crack! ;-)

(Incidentally, this relates to some code at the start of Chapter 5,
djangobook)

Thanks,

Ed


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