Re: Django export CSV file of two objects

2014-05-15 Thread hito koto

Hi,

i also write the views but the column was freaking After output to excel in 
this code.

def export_excel(request):
response = HttpResponse(mimetype='application/vnd.ms-excel; 
charset="Shift_JIS"')
response['Content-Disposition'] = 'attachment; filename=file.csv'
writer = csv.writer(response)
writer.writerow(["No","name","attendance", "leavework"]),
obj_all=attendance.objects.all().order_by("user_name")
for obj in obj_all:
row=[]
for field in attendance._meta.fields:
row.append(unicode(getattr(obj,field.name)).encode("cp932"))
writer.writerow(row)

obj =leavework.objects.all().order_by("user")
for a in obj:
row1=[]
for field in leavework._meta.fields:
row1.append(unicode(getattr(a,field.name)).encode("cp932"))
writer.writerow(row1)

return response





2014年5月15日木曜日 16時05分15秒 UTC+9 hito koto:
>
> Hello,
>
> I want to export file from database and from two objects;
>
> I'm use MYSQL, 
>
> I have two objects:
> 1, attendance object:
> 2. get_work object:
>
> I now can export one object's datas;
> So, i how can export datas of two objects;
>
> My the views.py is here:
>
> def export_excel(request):
> response = HttpResponse(mimetype='application/vnd.ms-excel; 
> charset="Shift_JIS"')
> response['Content-Disposition'] = 'attachment; filename=file.csv'
> writer = csv.writer(response)
> obj_all=attendance.objects.all()
> s = get_work object:
> for obj in obj_all:
> row=[]
> for field in Myattendance._meta.fields:
> row.append(unicode(getattr(obj,field.name)).encode("cp932"))
> writer.writerow(row)
>
> return response
>
> and the urls.py is here ;
>
> url(r'^export_excel/$', "staffprofile.views.export_excel"),
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75d2bd6c-a21b-4a74-97e4-0c1b9190320c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django export CSV file of two objects

2014-05-15 Thread hito koto
Hello,

I want to export file from database and from two objects;

I'm use MYSQL, 

I have two objects:
1, attendance object:
2. get_work object:

I now can export one object's datas;
So, i how can export datas of two objects;

My the views.py is here:

def export_excel(request):
response = HttpResponse(mimetype='application/vnd.ms-excel; 
charset="Shift_JIS"')
response['Content-Disposition'] = 'attachment; filename=file.csv'
writer = csv.writer(response)
obj_all=attendance.objects.all()
s = get_work object:
for obj in obj_all:
row=[]
for field in Myattendance._meta.fields:
row.append(unicode(getattr(obj,field.name)).encode("cp932"))
writer.writerow(row)

return response

and the urls.py is here ;

url(r'^export_excel/$', "staffprofile.views.export_excel"),

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ac6e407a-4b8a-46ca-a286-354d04dac3cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.