2👍
perhaps this prev question and answer of mine will help?
I access data from combined dynamically created tables via raw sql and send this data to be rendered in a Django-Tables2
If you want to specify the order of and indeed which columns are rendered, define a Meta Class as shown below (where ‘sequence’ is the order of the columns; nb ‘…’ just means ‘and all other columns’ – check out the documentary for Tables2 [search for ‘Swapping the position of columns’]):
def getTable(table_name):
cursor = runSQL(table_name,"""
SELECT * FROM subscription_exptinfo,%s
WHERE %s.id = subscription_exptinfo.id
;""" %(table_name,table_name))
exptData = dictfetchall(cursor)
class Meta:
attrs = {'class': 'paleblue'}
sequence = ('id','...')
attrs = {}
attrs['Meta'] = Meta
cols=exptData[0]
for item in cols:
if item=='timeStart':
attrs[str(item)] = tables.DateTimeColumn(format='d-m-Y g:i:s',short=False)
else:
attrs[str(item)] = tables.Column()
myTable = type('myTable', (TableReport,), attrs)
#TableOptions(table).sequence = ["Id","..."]
#print ".........................." + str(TableOptions(table).sequence)
return myTable(exptData)
Source:stackexchange.com