Closed ionescu77 closed 3 years ago
@ionescu77 I've merged in pull requests #35 and #36, which created a conflict. I think I've sorted out both properly, but could you please run a test against the latest on the main
branch before I push out a release and confirm that it works?
Hello, I will give it a try and report back. Thank you!
Excuse all, I deleted previous comment (it was my problem, I made some changes to serializers.py
in my project and it impacted XLSX generation, too).
So:
renderers.py
from main
branch into my project venv lib/python3.9/srf_renderer_xlsx
.RfidTag
-> Product
-> Category
)# api_views.py
class SecurityEventsGetXLSXViewset(XLSXFileMixin, ReadOnlyModelViewSet):
""" Generate XLSX File """
queryset = models.RfidTag.objects.all()
serializer_class = serializers.RfidTagNestedSerializer
renderer_classes = (XLSXRenderer,)
filename = 'RfidTagNested_export.xlsx'
# serializers.py
class RfidTagNestedSerializer(serializers.ModelSerializer):
product = ProductNestedSerializer()
class Meta:
model = models.RfidTag
fields = ['id', 'number', 'product', 'state', 'info']
[
{
"id": 1,
"number": "111abc",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
},
{
"id": 2,
"number": "111ABC",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
},
{
"id": 3,
"number": "111ABCD",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
},
{
"id": 4,
"number": "111ABCDE",
"product": {
"id": 3,
"name": "Prosop mic",
"ean": "222",
"description": "",
"category": {
"id": 2,
"name": "Textile Camera",
"description": ""
},
"info": []
},
"state": "I",
"info": []
},
{
"id": 5,
"number": "111ABCDEF",
"product": {
"id": 2,
"name": "Prosop mare",
"ean": "111",
"description": "",
"category": {
"id": 2,
"name": "Textile Camera",
"description": ""
},
"info": []
},
"state": "I",
"info": []
},
{
"id": 6,
"number": "string",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
},
{
"id": 7,
"number": "abc",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
},
{
"id": 8,
"number": "3034802c801c4ad6a5a4372e",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": "",
"info": []
}
]
And the XLSX:
The fix has been released in version 0.4.1: https://pypi.org/project/drf-renderer-xlsx/0.4.1/
there is already a fix, a PR (#36) opened by @paveloder
I have applied the fix locally and I can confirm it works.
My API was returning:
Before PR #36 patch
After PR #36 patch