I have a model that is referenced by a generic ListView, and feeds into a template. Attempts to create a table in the template give me a TypeError: not iterable
- what am I doing wrong?
Sample code
Class bookmodel(models.Model):
Book = models.CharField(max_length=255)
Author = models.CharField(max_length=255)
Views
Class bookview(generic.ListView):
model = bookmodel
template = “books.html”
Which generates an object_list
something like:
<Queryset [<bookmodel: Grapes of Wrath >, <bookmodel: I, Robot>]>
The template is laid out as follows:
{% extends ‘base.html’ %}
{% block content %}
<table>
<thead>
<tr>
<th> book </th>
<th> author </th>
</tr>
</thead>
<tbody>
{% for object in object_list %}
<tr>
{% for field in object %}
<td> {{ field }} </td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
But this fails with the aforementioned error.