I´m want to display dinamically a table in a html template. In the view I have:
def get_object( request ):
objects = MyObject.objects.all()
return render(request, 'table.html', { 'myObjects':objects, 'fields':ObjectAdmin.list_display})
then in 'table.html'
<thead class="tables-success">
<tr>
{% for field in fields %}
<th>{{ field }}</th>
{% endfor %}
</tr>
</thead>
{% for row in myObjects %}
<tr>
{% for field in fields %}
<td>{{ getattr(row, field) }}</td>
<!--<td>{{ row|getattr:field }}</td>-->
{% endfor %}
</tr>
{% endfor %}
and in admin.py
class MyObjectAdmin(admin.ModelAdmin):
list_display = [ 'name']#
list_per_page = 8
search_fields = [ 'name']
admin.site.register( Object, MyObjectAdmin )
but I m receiving the below error:
Could not parse the remainder: '(row, field)' from 'getattr(row, field)'
or
Exception Value: Invalid filter: 'getattr'
if I use
{{ row|getattr:field }}