afraid I'm a Newbie when it comes to Django.
I have a list of Dictionaries which I want to use to populate a Tables2 table. I don't know how to adapt the list of Dicts to work in Table2 :( The website suggests:
import django_tables2 as tables
data = [
{"name": "Bradley"},
{"name": "Stevie"},
]
class NameTable(tables.Table):
name = tables.Column()
table = NameTable(data)
I can't figure this out! Also, I will be using this view with many different sets of data and so my keys will change over views.
Here's an example of a list of Dictionaries (note that below, the two Dictionaries have the same keys; this always happens in each view; it is just that in different views there will be different sets of keys):
[{'trial2_click': u'left', 'timeStored': datetime.time(13, 35, 5), 'runOnWhatHardware': u'bla', 'id': 1L, 'timeStart': datetime.datetime(2012, 11, 2, 12, 54, 58, tzinfo=<UTC>), 'trial1_RT': 234.1, 'approxDurationInSeconds': 123L, 'timeZone': u'UTC', 'expt_id': 2L, 'trial1_click': u'right', 'trial2_RT': 2340L}, {'trial2_click': u'left', 'timeStored': datetime.time(13, 39, 15), 'runOnWhatHardware': u'bla', 'id': 2L, 'timeStart': datetime.datetime(2012, 11, 2, 12, 54, 58, tzinfo=<UTC>), 'trial1_RT': 234.1, 'approxDurationInSeconds': 123L, 'timeZone': u'UTC', 'expt_id': 2L, 'trial1_click': u'right', 'trial2_RT': 2340L}, {'trial2_click': u'left', 'timeStored': datetime.time(15, 32, 59), 'runOnWhatHardware': u'bla', 'id': 3L, 'timeStart': datetime.datetime(2012, 11, 2, 12, 54, 58, tzinfo=<UTC>), 'trial1_RT': 234.1, 'approxDurationInSeconds': 123L, 'timeZone': u'UTC', 'expt_id': 4L, 'trial1_click': u'right', 'trial2_RT': 2340L}]
Would much appreciate anyone's help :)
Create a
Table
subclass for each type of table you want to display. By type I mean set-of-columns. For example:solving my own Q, I found here a way of dynamically making a class at runtime:
and my working code: