1
我有這樣的代碼Python的出口日期時間爲csv
import csv
def export_failures_all(request):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="failures.csv"'
writer = csv.writer(response, delimiter=';', dialect = 'excel')
response.write(u'\ufeff'.encode('utf8'))
writer.writerow(['Maszyna', 'Wydział', 'Opis', 'Data dodania', 'Data rozpoczęcia naprawy', 'Data zakończenia naprawy', 'Zgłaszający', 'Przyjęte przez', 'Status'])
awarie = Awaria.objects.all().values_list('maszyna__nazwa', 'wydzial__nazwa', 'description', 'add_date', 'repair_date', 'remove_date', 'user__username', 'sur__username', 'status__nazwa').order_by('-id')
for awaria in awarie:
writer.writerow(awaria)
return response
這個問題我有它與add_date
,repair_date
,remove_date
因爲有DateTimeField
和csv文件,他們是用秒:
2017-02-14 09:50:19.271833+00:00
2017-02-14 08:38:09.362218+00:00
我想要這樣:
2017-02-14 09:50
2017-02-14 08:38
任何想法如何實現它?前
我怎麼能在values_list中管理這個? – azic
你可以用列表理解。我會更新我的答案。 – AJPennster
非常感謝。它完美的作品。 重要: 導入日期時間不是從datetime導入日期時間 – azic