I have a nested list as such:
olddataList = [['Route To Path/file1.txt', 'Route To Path/file2.txt', 'Route To Path/file3.txt'], [['Routing', 'Error'], ['Routing', 'Error'], ['Routing', 'Error']], [[['file1.txt', 'Mapping error']], [['file2.txt', 'Mapping error']],[['file3.txt', 'Mapping error']]], [['Summary 1 CODE018', 1], ['Summary 1 CODE018', 2], ['Summary 1 CODE018', 3]]]
dataList = dataList = [['Route To Path/file1.txt', 'Route To Path/file2.txt', 'Route To Path/file3.txt'], [['Routing', 'Error'], ['Routing', 'Error'], ['Routing', 'Error']], [[['file1a.txt', 'Mapping error'],['file1b.txt', 'Mapping error']], [['file2a.txt', 'Mapping error'],['file2b.txt', 'Mapping error']],[['file3a.txt', 'Mapping error'],['file3b.txt', 'Mapping error']]], [['Summary 1 CODE018', 1], ['Summary 1 CODE018', 2], ['Summary 1 CODE018', 3]]]
My intention is to generate a table like below:
Route To Path/file1.txt
Routing Error
file1a.txt Mapping error
file1b.txt Mapping error
Summary 1 CODE018
Route To Path/file2.txt
Routing Error
file2a.txt Mapping error
file2b.txt Mapping error
Summary 1 CODE018
Route To Path/file3.txt
Routing Error
file3a.txt Mapping error
file3b.txt Mapping error
Summary 1 CODE018
However with my code below, the table I get is as below. The final summary line should take only the first field of the list.
Route To Path/file1.txt
Route To Path/file2.txt
Route To Path/file3.txt
Routing Error
Routing Error
Routing Error
file1.txt Mapping error
file2.txt Mapping error
file3.txt Mapping error
I updated my code follows on suggestion by you Mr NavaneethaKrishnan, but I'm facing issue cause my Django environment do not recognize the table in bracket. However the way I implementing it wrong though cause it also not recognize argument such as 'dataList.1.outer_counter' as to replace your code 'dataList[1][i]'.
{% with dataList|length as ctr %}
{{ ctr }} <br />
<h4>{{ dataList.0.ctr }}</h4><br /> <!-- not recognize dataList.0.ctr -->
{% endwith %}
<table id="myTable">
{% load summary %}
{% for c in dataList %} <!-- unable to apply range like 0|range:ctr here -->
{% with forloop.counter0 as outer_counter %}
<tr>
{% for r in dataList.1.outer_counter %} <!-- not recognize dataList.1.outer_counter -->
<td>{{r}}</td>
{% endfor %}
</tr>
<tr>
{% for r in dataList.2.outer_counter.0 %}
<td>{{r}}</td>
{% endfor %}
</tr>
<tr>
{% for r in dataList.3.outer_counter %}
<td>{{r}}</td>
{% endfor %}
</tr>
</table>
{% endwith %}
{% endfor %}
Thank you in advance. Your helps is greatly appreciated.
[UPDATE] After do more research, finally I managed to get the solution. I post it here for anyone else who may need this for reference in future, as a token of appreciation for Mr NavaneethaKrishnan who had helped me.
{% for i in dataList.0 %}
{% with forloop.counter0 as outer_counter %}
{% if forloop.counter0 == outer_counter %}
<br />
<br />
<h4>{{ i }}</h4>
<table id="unitCheckDetailedTable">
<tr>
{% for i in dataList.1 %}
{% if forloop.counter0 == outer_counter %}
{% for j in i %}
<td>{{j}}</td>
{% endfor %}
{% endif %}
{% endfor %}
</tr>
{% for i in dataList.2 %}
{% if forloop.counter0 == outer_counter %}
{% for j in i%}
<tr>
{% for k in j%}
<td>{{k}}</td>
{% endfor %}
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</table>
{% endif %}
{% endwith %}
{% endfor %}
See Question&Answers more detail:
os