In order to show plural tables in a view using Django-tables2, I assigned plural tables to a table variable and use RequestConfig as follows,
views.py
tables = [ScheduleTable(qs_t2), ScheduleTable(qs_t2125), ScheduleTable(qs_gst)]
RequestConfig(request).configure(tables)
export_format = request.GET.get('_export', None)
if TableExport.is_valid_format(export_format):
exporter = TableExport(export_format, tables)
return exporter.response('tables.{}'.format(export_format))
return render(request, 'report/companies.html', {'table':tables})
"'list' object has no attribute 'prefixed_order_by_field" was the error message when 'RequestConfig' was executing. Do you know why?
I'm not sure whether this is the efficient way, but I got a result anyway. I just followed the answer from another question.
views.py
t2Table = ScheduleTable(qs_t2)
t2125Table = ScheduleTable(qs_t2125)
gstTable = ScheduleTable(qs_gst)
tables = {
't2Table': t2Table,
't2125Table': t2125Table,
'gstTable': gstTable,
}
RequestConfig(request).configure(ScheduleTable(qs_t2))
RequestConfig(request).configure(ScheduleTable(qs_t2125))
RequestConfig(request).configure(ScheduleTable(qs_gst))
return render(request, 'report/monthly_schedule.html', tables)
html
<p><h4>T2</h4>{% render_table t2Table %}</p>
<p><h4>T2125</h4>{% render_table t2125Table %}</p>
<p><h4>GST</h4>{% render_table gstTable %}</p>