diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 2642ae925e..29f9f5fe63 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -9,6 +9,8 @@ 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=[], + 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 ...]' @@ -16,12 +18,15 @@ class Command(BaseCommand): def handle(self, *app_labels, **options): from django.db.models import get_app, get_apps, get_models - format = options.get('format', 'json') - indent = options.get('indent', None) - show_traceback = options.get('traceback', False) + format = options['format'] + indent = options['indent'] + exclude = options['exclude'] + show_traceback = options['traceback'] + + excluded_apps = [get_app(app_label) for app_label in exclude] if len(app_labels) == 0: - app_list = get_apps() + app_list = [app for app in get_apps() if app not in excluded_apps] else: app_list = [get_app(app_label) for app_label in app_labels] diff --git a/docs/django-admin.txt b/docs/django-admin.txt index e14737c944..e8e3b54945 100644 --- a/docs/django-admin.txt +++ b/docs/django-admin.txt @@ -164,6 +164,22 @@ dumped. .. _custom manager: ../model-api/#custom-managers +--exclude +~~~~~~~~~ + +**New in Django development version** + +Exclude a specific application from the applications whose contents is +output. For example, to specifically exclude the `auth` application from +the output, you would call:: + + django-admin.py dumpdata --exclude=auth + +If you want to exclude multiple applications, use multiple ``--exclude`` +directives:: + + django-admin.py dumpdata --exclude=auth --exclude=contenttype + --format ~~~~~~~~