Closed Mte90 closed 2 months ago
The rendering code relies on customizing the Serializer
. Can you try passing the DRF generic one?
from rest_framework.serializers import Serializer
class Export(XLSXFileMixin, Viewset):
queryset = ""
serializer_class = Serializer
renderer_classes = (XLSXRenderer,)
filename = "export.xlsx"
http_method_names = [
"get",
]
def list(self, request):
new_output = {}
if self.request.query_params.get("export") == "data":
self.column_header = {
"titles": [
[...]
]
}
[my code here]
return self.response(new_output)
I tried with that one but didn't worked. Seems that required the various fields (with a field that doesn't exist in the serializer itself) define otherwise wasn't generating anything. Investigating the code seems that for any row and any value check if exist in the fields, so share like a json with the data is not working for this package (also the column headers were defined).
At the end I did it manually generating a csv for the moment.
So for reasons I have the endpoint and I do some various manipulation aggregating various stuff (without a model) and generating a dict with the data that I want in the exported file. An example of my code:
I get
So What is the right serializer to use to get just this dict in the generated file?