Django Dumpdata - format date and time output

696 Views Asked by At

Im using a puython script to dumpdata to a json file, and then from there convert it to csv.

call_command('dumpdata','document_manager.%s' % model_name,format='json',indent=2,stdout=output)

This is the date and time from the generated JSON file:

 "timestamp": "2014-01-07T08:29:16.857Z", 
 "date": "2014-01-07T08:29:13Z", 

Is it possible to output it in this formatting rather?

2014-01-07 08:29:16.000857
1

There are 1 best solutions below

0
mawimawi On

No, it is not possible with the dumpdata command. You would need to post process your json file with e.g. sed, awk or even a little python script.

But if you just need to output your table as CSV, have a look at https://djangosnippets.org/snippets/2240/