Created
July 21, 2022 19:23
-
-
Save vb64/ada42ba2b104e96b63260ce88fe61b0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import csv | |
| def queryset2csv(qset): | |
| """Converts a Django queryset to the content of a csv file.""" | |
| out = io.StringIO() | |
| writer = csv.writer(out, delimiter=';', lineterminator='\n') | |
| for row in qset: | |
| writer.writerow([row.field1, row.field2, ...]) | |
| content = out.getvalue() | |
| out.close() | |
| return content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment