Skip to content

Instantly share code, notes, and snippets.

@danner
Created August 8, 2017 16:54
Show Gist options
  • Save danner/9a179b0b3e8f5093a07e62ed7f32cadd to your computer and use it in GitHub Desktop.
Save danner/9a179b0b3e8f5093a07e62ed7f32cadd to your computer and use it in GitHub Desktop.
# 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