Reputation: 6304
I am new to django,
I've got models with data that I want to display in a table format.
I'm used to using gridviews in asp.net and I am looking for an alternative.
Is the best way to do this using template iteration tags and is there some sort of tutorials online showing examples on how to do this?
Upvotes: 1
Views: 1435
Reputation: 1020
Django explicitly avoids providing front end widgets (like ASP.NET gridviews or Rails scaffolding).
If you want this in a regular template you gotta roll your own:
{% if list %}
<table>
<tr>
<th> Foo </th>
<th> Bar </th>
</tr>
{% for item in list %}
<td>{{item.foo}}</td>
<td>{{item.bar}}</td>
{% empty %}
<td colspan="2">No items.</td>
{% endfor %}
</table>
{% endif %}
However if you want to provide admins with quick ways to edit/view data you can use the Django Admin Site. Make sure you have the django.contrib.admin
in your INSTALLED_APPS
setting and then (in the most trivial example) just create a admin.py
for your app with:
from django.contrib import admin
from myproject.myapp.models import Author
admin.site.register(Author)
Upvotes: 3