Ticket #12572: 12572_syncdb.diff
File 12572_syncdb.diff, 3.1 KB (added by , 15 years ago) |
---|
-
django/core/management/commands/syncdb.py
2 2 import sys 3 3 4 4 from django.conf import settings 5 from django.core.management.base import NoArgsCommand5 from django.core.management.base import BaseCommand, CommandError 6 6 from django.core.management.color import no_style 7 7 from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal 8 8 from django.db import connections, transaction, models, DEFAULT_DB_ALIAS 9 9 from django.utils.importlib import import_module 10 from django.core.exceptions import ImproperlyConfigured 10 11 11 12 12 class Command( NoArgsCommand):13 option_list = NoArgsCommand.option_list + (13 class Command(BaseCommand): 14 option_list = BaseCommand.option_list + ( 14 15 make_option('--noinput', action='store_false', dest='interactive', default=True, 15 16 help='Tells Django to NOT prompt the user for input of any kind.'), 16 17 make_option('--database', action='store', dest='database', … … 19 20 make_option('-e', '--exclude', dest='exclude',action='append', default=[], 20 21 help='App to exclude (use multiple --exclude to exclude multiple apps).'), 21 22 ) 22 help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 23 help = ("Create the database tables for the apps in argument list or for all " 24 "apps in INSTALLED_APPS if no app names given whose tables haven't already been created.") 25 args = '[appname ...]' 23 26 24 def handle _noargs(self, **options):27 def handle(self, *app_labels, **options): 25 28 26 29 verbosity = int(options.get('verbosity', 1)) 27 30 interactive = options.get('interactive') … … 32 35 33 36 # Import the 'management' module within each installed app, to register 34 37 # dispatcher events. 35 for app_name in settings.INSTALLED_APPS:38 for app_name in app_labels or settings.INSTALLED_APPS: 36 39 try: 37 40 import_module('.management', app_name) 38 41 except ImportError, exc: … … 59 62 created_models = set() 60 63 pending_references = {} 61 64 62 excluded_apps = set(models.get_app(app_label) for app_label in exclude) 63 included_apps = set(app for app in models.get_apps() if app not in excluded_apps) 65 try: 66 excluded_apps = set(models.get_app(app_label) for app_label in exclude) 67 except ImproperlyConfigured, e: 68 raise CommandError(e) 64 69 70 if len(app_labels) == 0: 71 included_apps = set(app for app in models.get_apps() if app not in excluded_apps) 72 else: 73 try: 74 included_apps = set(models.get_app(app_label) for app_label in app_labels if not app_label in exclude) 75 except ImproperlyConfigured, e: 76 raise CommandError(e) 77 65 78 # Create the tables for each model 66 79 for app in included_apps: 67 80 app_name = app.__name__.split('.')[-2]