Using djt2 v0.15/dj1.6/pyth2.6.6
djt2 doc example views file for multiple tables:
def people_listing(request) :
config = RequestConfig(request)
table1 = PeopleTable(Person.objects.all(), prefix="1-")
table2 = PeopleTable(Person.objects.all(), prefix="2-")
config.configure(table1)
config.configure(table2)
return render(request, "people_listing.html",
{"table1": table1, "table2": table2})
This example first of all seems incorrect as to the quoted "table1", "table2" parameters. My tests show the the definition name "people_list" needs to be used in the quotes, at least on a single table. Besides why would anyone want to display the same table twice? Is this a bad example? Here is my app trying to use this structure:
def AvLabVw(request):
config = RequestConfig(request)
cmutbl = CmuTable(CmuVersion.objects.all(), prefix="1-")
simtbl = SimTable(Simulator.objects.all(), prefix="2-")
config.configure(cmutbl)
config.configure(simtbl)
return render(request, "AvRelInfo.html", {"AvLabVw":cmutbl, "AvLabVw":simtbl})
The url file picks up on AvLabVw and the html template uses render_table.
{% render_table AvLabVw %}
What happens with this code is only one table is still displayed, whichever is last on the return render line.
Elsewhere in the doc it says SingleTableView with get_context_data needs to be used, which I haven't figured out yet...
I have an attempt on this style implementation, I think it needs a table object and a list object?
views.py
from django_tables2 import views from django_tables2 import SingleTableView from django_tables2 import SingleTableMixin from django.shortcuts import render from django_tables2 import RequestConfig def SimVers_lst(request): return render(request, 'AvRelInfo.html', {'SimVers_lst' : Simulator.objects.all()}) def AvLabVw(request): config = RequestConfig(request) simlst = SimVers_lst(Simulator.objects.all()) table = CmuTable(CmuVersion.objects.all(), prefix="1-") Stv = views.SingleTableView() multitbl = Stv.get_context_data() config.configure(multitbl) return render(request, "AvRelInfo.html", { "AvLabVw" : multitbl })
barfs at {% render_table AvLabVw %}
in the html template with the usual catch-all
"ValueError at /AvCtlapp/ Expected table or queryset, not 'str'."
... getting some garbage... I guess I can try to see what it gets in a shell if I can set up that test...
Thanks for any help...
Joe
PS: Is a custom render needed, and how would that look?