wharton / drf-excel

An XLSX spreadsheet renderer for Django REST Framework.
BSD 3-Clause "New" or "Revised" License
212 stars 40 forks source link

ManyToMany relationship fail when rendered as XLSX #45

Closed rptmat57 closed 2 years ago

rptmat57 commented 2 years ago

Hi, Unless I missed something obvious, when I tried to export using XLSX, I get an error due to ManyToMany fields. Specifically, line 332 of renderers.py: https://github.com/wharton/drf-renderer-xlsx/blob/82af43b879aad2a37b0d1115f5f830bf5c822314/drf_renderer_xlsx/renderers.py#L330-L332

The problem seems to be that if it's a list of non string objects, it throws an error. And by default for ManyToMany fields, django sends back a list of int (the ids) It would probably make sense to flatten the list by calling str() on each element of the list?

Something like this: list_sep.join(map(str,v))

willtho89 commented 2 years ago

@rptmat57 can you provide some example code to reproduce the error?

rptmat57 commented 2 years ago

here is a small sample project. after creating a superuser and logging in to /admin, if you create a publication, then an article with that publication selected, when you go to /api and try to export articles in Excel it will fail xlsx_renderer_project.zip