1 from django.core.management import setup_environ
2 from prawokultury import settings
6 print "give me file name pls"
9 setup_environ(settings)
11 from contact.models import *
14 ("Created", 'created_at'),
16 ("Contact", 'contact'),
20 conts = Contact.objects.all().order_by("created_at")
24 json_fields = tuple(conts[0].body.keys())
26 # The inverse of zip is zip
27 headers, fields = zip(*export_info)
28 rows = [headers + json_fields]
30 qs = Contact.objects.filter(pk=cont.id)
31 rows.append([unicode(v) for v in qs.values_list(*fields)[0]] + [unicode(qs[0].body.get(f, 'N/A')) for f in json_fields])
34 with open(sys.argv[1],'w') as ofile:
35 o = csv.writer(ofile, dialect='excel')
37 o.writerow([r.encode('utf-8') for r in row])