Dear Team,

I am trying to export filtered data from a django model, but I get an empty
file. But when I remove the filter and add all, it works.

Kindly assist to know how to export filtered data. Below is my code

def exportexpenes(request):
filter_val1=request.POST.get("filter1")
filter_val2=request.POST.get("filter2")
response=HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=expenses' + str(
datetime.datetime.now())+'.csv'
writer = csv.writer(response)
writer.writerow(['Category','Beneficiary','Description','Operation Date',
'Amount','Account Number','Paymrnt Date','Status'])
expes = EXPENSES.objects.filter(Q(created_at__range=[filter_val2,filter_val1
]))
# expes = EXPENSES.objects.all()
for exp in expes:
writer.writerow([exp.category,exp.beneficiary,exp.description,
exp.date_of_operation,exp.amount,exp.account_number,exp.payment_date,
exp.status])
return response

regards,
-- 
*Eugene*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHuqV0Py%3D05eyu%3Dv%3DDFBm%2B1y9v-e2AbmVn2Bvj66jG8MZA%40mail.gmail.com.

Reply via email to