I have a list of dict that look like this:
[set([u'meal', '0:08:35.882945']),
set([0, u'personal']),
set([0, u'sleep']),
set([0, u'transport']),
set([0, u'work'])]
That I made from :
[u'meal',u'personal', u'sleep', u'transport', u'work']
['0:08:35.882945', 0, 0, 0, 0]
With this command:
nob = [{m,n} for m,n in zip(cats,tot3)]
How can I turn this into a django-tables2 table?
I tried this :
# tables.py
class Small_table (tables.Table):
category = tables.Column(verbose_name="category")
class Meta:
attrs = {"class": "paleblue"}
# views.py
nt = Small_table(nob)
RequestConfig(request).configure(nt)
But the table has one column of dashes rather than my data, what should I change?
this is what i ended up doing:
in my tables.py:
in my view
and in the template:
I'm not familiar with this django-tables app, but if your goal is to simply display your data in a table, I would do it like that:
Your data structure is much too complicated. Simply create a list of tuples and return it as your template context.
In your template, you can then do:
This creates a row with two cells in the table for each entry in
nob
. Now you may see why a list of sets is not a good idea here. Sets don't preserve the ordering of elements, i.e.{{ i }}
would sometime be taken from lista
and sometimes from listb
whereas you want{{ i }}
always to be taken from lista
and{{ j }}
always to be taken from listb
.