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...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/93a559c8-bc77-44b7-8499-469db0f224e5%40Spark.
African Institute for Mathematical Sciences (AIMS Cameroon)Crystal Garden-Lime, Cameroon
Bsc in Computer Science
UR-Nyagatare Campus
Email: eugene....@aims-cameroon.org eugenet...@gmail.com
Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABxpZHvFzd3N1ur5%3DbzmDtJUUAF3BfjamMg7pra-RCL5ffjZCw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABxpZHvFzd3N1ur5%3DbzmDtJUUAF3BfjamMg7pra-RCL5ffjZCw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABxpZHvFzd3N1ur5%3DbzmDtJUUAF3BfjamMg7pra-RCL5ffjZCw%40mail.gmail.com.
#settings.py
FOO = “foo”
When you want to use it
e.g views.py
from django.conf import settings
FOO_VARIABLES = settings.FOO
BAR = “bar”
To use it
import os
BAR_VARIALBE = os.getenviron.get(“BAR”)
Regards
Ngallen Ramadhan
T: +255 765 889 960 | M: +255 715 200 997
Emial: rama...@maycom.co.tz | Skype: ngallen2
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKHnA%2BXTpYHy%2BDDmwe1vpcpLKScp2NLbS0gN_TAiqE_i-mkDCA%40mail.gmail.com.