summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-02-28 05:35:22 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-02-28 05:35:22 +0000
commitdb2a95f6f58f5593dbcee8dcf51f3e9d71449708 (patch)
tree0732f88402e8d4b58f80d9f21c6dc3844512e746 /django
parentb337884fcf6b2c1934d380dd99bbe485d3b88f3a (diff)
Fixed #5610 -- Added the ability for dumpdata to take individual model names, as well as entire applications. Thanks to David Reynolds for his work on this patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9921 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/dumpdata.py44
1 files changed, 37 insertions, 7 deletions
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index 2559d57104..eecf9404f3 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -1,3 +1,4 @@
+from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
@@ -9,14 +10,14 @@ class Command(BaseCommand):
help='Specifies the output serialization format for fixtures.'),
make_option('--indent', default=None, dest='indent', type='int',
help='Specifies the indent level to use when pretty-printing output'),
- make_option('-e', '--exclude', dest='exclude',action='append', default=[],
+ make_option('-e', '--exclude', dest='exclude',action='append', default=[],
help='App to exclude (use multiple --exclude to exclude multiple apps).'),
)
help = 'Output the contents of the database as a fixture of the given format.'
args = '[appname ...]'
def handle(self, *app_labels, **options):
- from django.db.models import get_app, get_apps, get_models
+ from django.db.models import get_app, get_apps, get_models, get_model
format = options.get('format','json')
indent = options.get('indent',None)
@@ -26,9 +27,34 @@ class Command(BaseCommand):
excluded_apps = [get_app(app_label) for app_label in exclude]
if len(app_labels) == 0:
- app_list = [app for app in get_apps() if app not in excluded_apps]
+ app_list = dict([(app, None) for app in get_apps() if app not in excluded_apps])
else:
- app_list = [get_app(app_label) for app_label in app_labels]
+ app_list = {}
+ for label in app_labels:
+ try:
+ app_label, model_label = label.split('.')
+ try:
+ app = get_app(app_label)
+ except ImproperlyConfigured:
+ raise CommandError("Unknown application: %s" % app_label)
+
+ model = get_model(app_label, model_label)
+ if model is None:
+ raise CommandError("Unknown model: %s.%s" % (app_label, model_label))
+
+ if app in app_list.keys():
+ if app_list[app] and model not in app_list[app]:
+ app_list[app].append(model)
+ else:
+ app_list[app] = [model]
+ except ValueError:
+ # This is just an app - no model qualifier
+ app_label = label
+ try:
+ app = get_app(app_label)
+ except ImproperlyConfigured:
+ raise CommandError("Unknown application: %s" % app_label)
+ app_list[app] = None
# Check that the serialization format exists; this is a shortcut to
# avoid collating all the objects and _then_ failing.
@@ -41,9 +67,13 @@ class Command(BaseCommand):
raise CommandError("Unknown serialization format: %s" % format)
objects = []
- for app in app_list:
- for model in get_models(app):
- objects.extend(model._default_manager.all())
+ for app, model_list in app_list.items():
+ if model_list is None:
+ model_list = get_models(app)
+
+ for model in model_list:
+ objects.extend(model.objects.all())
+
try:
return serializers.serialize(format, objects, indent=indent)
except Exception, e: