I'm trying to add a counter on the first column of a table using django-tables2, but the solution below is only showing all 0 under the # column. How should I add a column that will have a column that numbers the rows?
tables.py:
import django_tables2 as tables
from profiles.models import Track
import itertools
counter = itertools.count()
class PlaylistTable(tables.Table):
priority = tables.Column(verbose_name="#", default=next(counter))
class Meta:
model = Track
attrs = {"class": "paleblue"}
orderable = False
fields = ('priority', 'artist', 'title')
My template:
{% render_table table %}
lambda _: next(counter)
, although even if that worked it would be pretty ugly/hacky. – Broads