summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnubhav Joshi <anubhav9042@gmail.com>2014-03-23 10:40:12 +0530
committerAnubhav Joshi <anubhav9042@gmail.com>2014-03-25 13:47:03 +0530
commitf34e8fc890d44f4f913fe812f2cdeb5666f0fa27 (patch)
tree09218e12baa21162a180be23219a8a41bd85ef21 /django
parent416a8580232075d569cf3c386a97067884c67a60 (diff)
Fixed #22257 -- Added file output option to dumpdata command.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/dumpdata.py5
1 files changed, 4 insertions, 1 deletions
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