Created
August 8, 2017 16:54
-
-
Save danner/9a179b0b3e8f5093a07e62ed7f32cadd 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
# Python 2.7: | |
from io import BytesIO | |
def get_dumpdata_results(self): | |
# https://stackoverflow.com/questions/16075789/how-to-use-call-command-with-dumpdata-command-to-save-json-to-file#16076115 | |
buf = BytesIO() | |
management.call_command('dumpdata', stdout=buf) | |
buf.seek(0) | |
return json.loads(buf.read()) | |
# Python 3.6 | |
from io import StringIO | |
def get_dumpdata_results(self): | |
# https://stackoverflow.com/questions/16075789/how-to-use-call-command-with-dumpdata-command-to-save-json-to-file#16076115 | |
buf = StringIO() | |
management.call_command('dumpdata', stdout=buf) | |
buf.seek(0) | |
return json.loads(buf.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment