Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Download and export data to CSV

I have managed to develop an export button which allows users to download all approved orders

`def orders_download(request):
response=HttpResponse(content_type='text/csv')
response['Content- 
Disposition']='attachment;filename="all_orders.csv"'
query=Order.objects.all()

writer=csv.writer(response)
writer.writerow(['DESCRIPTION','COST','QUANTITY','TOTAL_COST','CATEGORY','STATUS','DATE_ORDERED'])


return `response

its downloading but not returning all rows as required.
what is it am missing?

have tried looping but its returning one row multiple times

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you should loop to ensure all the rows are written

for rows in query:
        writer.writerow([rows.description,rows.cost,rows.quantity,rows.total_cost,rows.category,rows.status,rows.order_date])
return response
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading