I have a django app that renders querysets into tables.
I need to perform a few modifications of the underlying querysets and it would be the most convenient to convert the querysets into dataframes, do some magic there and then convert the resulting dataframe back into a queryset so that I can feed it into the existing render.
Converting a queryset into a dataframe seems straightforward, but I ccan't find a way to convert that back.
tables.py
class StuffTable(tables.Table):
class Meta:
model = Stuff
template_name = 'django_tables2/semantic.html'
views.py
import django_pandas.io as dpd
from django_tables2.tables import Table
from .models import Stuff
from .tables import StuffTable
def index(request):
context = dict()
template = 'gui/index.html'
stuff = Stuff.objects.all()
# do pandas stuff with the data
df = dpd.read_frame(stuff)
df = ...
modified_stuff = convert_df_back_to_qs(df) # how to do this?
table = StuffTable(modified_stuff)
context['table'] = table
return render(request, template, context)
How can I do this?
EDIT: The reason why I want to convert back is that the html files look like
{% load render_table from django_tables2 %}
<body>
{% render_table table %}
</body>
So, if I can convert the data back into a queryset I would not need to touch any of the html files.