class ExportTrsanctionView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
f = TransactionFilter(request.session.get('export_journal'))
queryset = f.qs.prefetch_related(
'journal_set' , 'journal_set__account'
).filter(journal__account__owner=request.user).distinct()
pseudo_buffer = Echo()
writer = csv.writer(pseudo_buffer)
writer.writerow(['Date', 'Account', 'balance', 'transaction type' , 'comment'])
response = StreamingHttpResponse(
streaming_content=(writer.writerow(
[transaction.date , journal.account , journal.balance , journal.transaction_type , transaction.comment ]
) for transaction in queryset for journal in transaction.journal_set.all()
),
content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="journal{}.csv"'.format(timezone.now().isoformat())
return response
when i try to download data the header not included and i don’t know why
the header should contain this line
writer.writerow(['Date', 'Account', 'balance', 'transaction type' , 'comment'])