Hey All,I'm using the generic views and trying to build a HTML table where both the rows and columns are generated dynamically. Simplified example follows.
I am having a problem though in that I can't work out if it is possible to reference an attribute of a model using a template variable. In Smarty it would be something like {$model.$attribute}
Is this possible in Django or am I going to have to write a template tag to do this for me?
-D ===== urls.py ===== view_dict = { 'queryset': ContactGroup.objects.all(), 'template_name': 'generic_list.html', 'extra_context': { 'columns': ('id', 'name', 'description')}, } urlpatterns += patterns('django.views.generic.list_detail', ('^contact-groups/$', 'object_list', view_dict) ) ===== generic_list.html ===== {% extends "base.html" %} {% block content %} <table> <tr> {% for column in columns %} <th>{{ column|capfirst }}</th> {% endfor %} </tr> {% for object in object_list %} <tr> {% for column in columns %} <td>{{ object.column }}</td> <----- Problem is here {% endfor %} </tr> {% endfor %} </table> {% endblock %}
signature.asc
Description: OpenPGP digital signature