I'm populating table using using for loop in django list view.
While populating I want to display serial number as well in the list.
{% for Attendee in filter.qs %}
{% if Attendee.checkin %}
<tr>
<td> Serial no. </td>
<td>{{ Attendee.roll_no }}</td>
<td>{{ Attendee.name }}</td>
<td>{{ Attendee.branch }}</td>
</tr>
{% endif %}
As I'm using filter to display the results, it is not possible to maintain serial number in models.
I want something like this:

What are the other possible ways I can use to put serial numbers in list?
EDIT:
After using {{ forloop.counter }} in list, the serials aren't continuous. eg:

You can access current iteration of the loop via forloop.counter(1-indexed) or forloop.counter0(0-indexed). For your case:
{% for Attendee in filter.qs %}
{% if Attendee.checkin %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ Attendee.roll_no }}</td>
<td>{{ Attendee.name }}</td>
<td>{{ Attendee.branch }}</td>
</tr>
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With