Comparing multiple forloop.counter values in templates


I have a homework assignment that wants us to create a gradebook table that will keep the same values entered in prior to hitting submit and I am having trouble actually getting those values set to stay, but I do have the scores for the “assignments” in a table, so I know it can be done but I am just a rookie with django templates and what not.

I have tried to do the render method multiple times and loop through this score list but obviously rendering the table multiple times comes with its own issues, and now I am currently trying to loop through the lists of students, assignments, and grades (in probably a very inefficient way) in the Django template, but to get the expected results I would have to have 3 nested loops and only create a table’s cell if the index of the outter two loops match certain constraints of the inner loop (see code below).

VIEWS.PY:

scores = list(models.Grade.objects.all().values_list('score', flat=True)) students = list(models.Student.objects.all().values_list('id', flat=True)) items = list(models.Item.objects.all().values_list('item_name', flat=True)) return render(request, 'main/index.html', {"row": students, "col": items, = "scores": scores}) 

INDEX.HTML:

{% for i in row %}       <tr><th>{{i}}</th>       {% for j in col %}           {%  for k in scores %}               {% if forloop.counter == ((forloop.parentloop.counter + 1) * (forloop.parentloop.parentloop.counter + 1) - 1 %}                 <td><input name="{{i}}_{{j}}" type="number" value="{{ k }}"/></td>               {% endif %}           {% endfor %}       {% endfor %}       </tr> {% endfor %} 

The expected results would end up rendering the table with the same cell values as what was last entered, or what was in the Grade’s table, but the issue is that in the if loop it throws an error saying “ID or literal expected” and it seems to come from modifying the **loop.counter values.