django - How to use call_command with dumpdata command to save json to file -
i trying use call_command
method call dumpdata command
. manually, use follows save data file.
python manage.py dumpdata appname_one appname_two > /path/to/save/file.json
and saves json file. now, in situation need call command using call_command
method.
i able print out json command using following:
from django.core.management import call_command call_command('dumpdata', 'appname_one', 'appname_two')
is there way can save given data file command line?
had redirect sys.stdout
file in order achieve above. like.
import sys django.core.management import call_command sysout = sys.stdout sys.stdout = open('filename.json', 'w') call_command('dumpdata', 'appname_one', 'appname_two') sys.stdout = sysout
Comments
Post a Comment