On Sep 23, 6:05 pm, Chris Withers <ch...@simplistix.co.uk> wrote: > Hi All, > > I have this view function: > > def index(request,model,pk=None): > > return list_detail.object_list( > request, > queryset=model.objects.all(), > paginate_by=10, > template_name='index.html', > extra_context=dict( > column_titles = [f.name for f in model._meta.fields], > ) > ) > > Where index.html is: > > <table> > <tr> > {% for title in column_titles %} > <th>{{title}}</th> > {% endfor %} > </tr> > {% for object in object_list %} > <tr> > {% for name in column_titles %} > <td> > {{*what goes here*}} > </td> > {% endfor %} > </tr> > {% endfor %} > </table> > > What do I put in the marked spot to be the equivalent of > getattr(object,name)? > > cheers, > > Chris >
It's an intentional limitation of the template language that you can't do that. You'll need to write a custom tag or filter - luckily it can be done very trivially as a filter: @register.filter def get_attr(obj, val) return getattr(obj, val) Now in the template: {{ object|getattr:name }} -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---