My Django install uses a PostgreSQL backend.
I am doing the following in a Django view:
completedItems = Completed.objects.filter(user_id=1)
return HttpResponse(completedItems.values('item_id','item_name','event_datetime','item_id__item_name'))
For the date timefield, this returns:
'event_datetime': datetime.datetime(2014, 6, 4, 0, 49, 38, tzinfo=<UTC>)
I am trying to serialize the return using json.dumps, and this formatting is giving me grief. What is the best way to reformat the datetime return from the query so I can serialize it properly?
I tried to use:
datetime.strptime('event_datetime',"datetime.datetime(%Y, %m, %d, %H, %M, %S, tzinfo=<%Z>)")
but it complains that the date does not match the format string.
strptimeis for converting a string to a datetime, but you seem to have a datetime already.