7 option_list = BaseCommand.option_list + ( |
7 option_list = BaseCommand.option_list + ( |
8 make_option('--format', default='json', dest='format', |
8 make_option('--format', default='json', dest='format', |
9 help='Specifies the output serialization format for fixtures.'), |
9 help='Specifies the output serialization format for fixtures.'), |
10 make_option('--indent', default=None, dest='indent', type='int', |
10 make_option('--indent', default=None, dest='indent', type='int', |
11 help='Specifies the indent level to use when pretty-printing output'), |
11 help='Specifies the indent level to use when pretty-printing output'), |
|
12 make_option('-e', '--exclude', dest='exclude',action='append', default=[], |
|
13 help='App to exclude (use multiple --exclude to exclude multiple apps).'), |
12 ) |
14 ) |
13 help = 'Output the contents of the database as a fixture of the given format.' |
15 help = 'Output the contents of the database as a fixture of the given format.' |
14 args = '[appname ...]' |
16 args = '[appname ...]' |
15 |
17 |
16 def handle(self, *app_labels, **options): |
18 def handle(self, *app_labels, **options): |
17 from django.db.models import get_app, get_apps, get_models |
19 from django.db.models import get_app, get_apps, get_models |
18 |
20 |
19 format = options.get('format', 'json') |
21 format = options.get('format','json') |
20 indent = options.get('indent', None) |
22 indent = options.get('indent',None) |
|
23 exclude = options.get('exclude',[]) |
21 show_traceback = options.get('traceback', False) |
24 show_traceback = options.get('traceback', False) |
22 |
25 |
|
26 excluded_apps = [get_app(app_label) for app_label in exclude] |
|
27 |
23 if len(app_labels) == 0: |
28 if len(app_labels) == 0: |
24 app_list = get_apps() |
29 app_list = [app for app in get_apps() if app not in excluded_apps] |
25 else: |
30 else: |
26 app_list = [get_app(app_label) for app_label in app_labels] |
31 app_list = [get_app(app_label) for app_label in app_labels] |
27 |
32 |
28 # Check that the serialization format exists; this is a shortcut to |
33 # Check that the serialization format exists; this is a shortcut to |
29 # avoid collating all the objects and _then_ failing. |
34 # avoid collating all the objects and _then_ failing. |