Just to follow up for the archives.What I was after is a getattr filter for the templates. Searching djangosnippets.org has found a couple. This one seems to do what I need:
http://www.djangosnippets.org/snippets/411/ Regards Darryl Darryl Ross wrote:
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 %}
-- Darryl Ross Director AFOYI, "Information Technology Solutions" p 08 7127 1831 m 0400 206 443 f 08 8425 9607 e [EMAIL PROTECTED]
signature.asc
Description: OpenPGP digital signature