i am stuck in one problem.. i am trying to write to excel file what i do in my app.
studium = unt_stelle.objects.all().order_by("stand__nick")
formatter = ExcelFormatter()
simpleStyle = ExcelStyle(vert=2,wrap=1)
formatter.addBodyStyle(simpleStyle)
formatter.setWidth('name,clicks,stand.nick,berufsfelder,bereich',3000)
formatter.setWidth('erfahrung',1000)
formatter.setWidth('studiengaenge',1000)
formatter.setWidth('status',1000)
formatter.setWidth('id',500)
simple_report = ExcelReport()
simple_report.addSheet("TestSimple")
filter = ExcelFilter(order='id,name,clicks,status,stand.nick,erfahrung,studiengaenge,berufsfelder,bereich')
simple_report.addQuerySet(studium,REPORT_HORZ,formatter,filter)
response = HttpResponse(simple_report.writeReport(),mimetype='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename=stellen_dump.xls'
return response
my problem is that if i give 'studiengaenge' as a column, i get weird queryset in this column, not a normal string, stu开发者_Python百科diengaenge is a ManyToManyField. how can i manage this so that i have only 3 items from 'studiengaenge' field with some small design like with "-" in between of each items...?
Thanks
From what I remember, the "weird queryset" you get from the many-to-many can be accessed as an array. You can iterate through it and build a string.
精彩评论