Last Updated: February 25, 2016
·
907
· boblefrag

Generic csv exporter for Django

http://snippet.gabory.fr/snippet/7/

This function take a list of objects and a list of tuple. Each tuple is formated like this :
First the name of the column as it must appear on the csv file
Second the corresponding field on the model or a property.

If you don't give a file name argument it will use StringIO to generate the csv.
With a file, you will save the result on the disk. It is then up to you to give it back to the user asking for the csv file. In teh code we expect settings.PROJECTPATH to be the path of your django project and custommedia the directory where you put media.
Change them to fit your needs