From f34e8fc890d44f4f913fe812f2cdeb5666f0fa27 Mon Sep 17 00:00:00 2001 From: Anubhav Joshi Date: Sun, 23 Mar 2014 10:40:12 +0530 Subject: Fixed #22257 -- Added file output option to dumpdata command. --- django/core/management/commands/dumpdata.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 827f2b6c50..045bc96397 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -36,6 +36,8 @@ class Command(BaseCommand): help="Only dump objects with given primary keys. " "Accepts a comma separated list of keys. " "This option will only work when you specify one model."), + make_option('-o' ,'--output', default=None, dest='output', + help='Specifies file to which the output is written.'), ) help = ("Output the contents of the database as a fixture of the given " "format (using each model's default manager unless --all is " @@ -47,6 +49,7 @@ class Command(BaseCommand): indent = options.get('indent') using = options.get('database') excludes = options.get('exclude') + output = options.get('output') show_traceback = options.get('traceback') use_natural_keys = options.get('use_natural_keys') if use_natural_keys: @@ -155,7 +158,7 @@ class Command(BaseCommand): serializers.serialize(format, get_objects(), indent=indent, use_natural_foreign_keys=use_natural_foreign_keys, use_natural_primary_keys=use_natural_primary_keys, - stream=self.stdout) + stream=open(output, 'w') if output else self.stdout) except Exception as e: if show_traceback: raise -- cgit v1.3