I want to use a nested for loop to iterate through all the items of my model, but also through the selection of the fields I decide in this model only!
The idea is to display all the items in a data table but only with the fields I have chosen.
Here is what I have tried:
<table class="table table-bordered" id="example" style="text-align: center; font-size: 14px;">
<thead class="table-success">
<tr>
{% for verb in verbose %}
<th>{{ verb }}</th>
{% endfor %}
</tr>
</thead>
<tr>
{% for test in tests %}
{% for f in fields %}
<td class="body-table" style="padding: 1px;">{{test}}.{{f}} </td>
{% endfor %}
{% endfor %}
</tr>
</table>
I let the error which I think is self explainable {{test}}.{{f}}
Below is the snippet of the view:
def test_home(request):
verbose = Test().get_all_fields_verbose()
fields = Test().get_all_fields_names()
test_list = Test.objects.all().order_by('-created_at')
system1= System0.objects.all()
form = TestForm()
items=len(verbose)
context = {"tests":test_list,"systems":system1, "form":form,"items":items, "verbose":verbose,"fields":fields }
return render(request, 'test_simple_home.html', context )