feat: Export relationships with answers

See #27
See #29
Resolves #25
This commit is contained in:
James Graham
2020-04-01 13:15:48 +01:00
parent 76ae447cc6
commit 76270c4572
3 changed files with 35 additions and 12 deletions

View File

@@ -15,8 +15,9 @@ class CsvExportView(LoginRequiredMixin, BaseListView):
def render_to_response(self, context: typing.Dict) -> HttpResponse:
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = f'attachment; filename="{self.get_context_object_name(self.object_list)}.csv"'
serializer = self.serializer_class(self.get_queryset(), many=True)
# Force ordering by PK - though this should be default anyway
serializer = self.serializer_class(self.get_queryset().order_by('pk'), many=True)
writer = csv.DictWriter(response, fieldnames=serializer.child.column_headers)
writer.writeheader()