Ticket #1397: syncdb_initial_sql_data.diff

File syncdb_initial_sql_data.diff, 2.5 KB (added by anonymous, 19 years ago)

makes the django_package thingy work again

  • django/branches/magic-removal/django/core/management.py

     
    2626
    2727INVALID_PROJECT_NAMES = ('django', 'test')
    2828
     29def _get_app_label(app):
     30    from django.db.models import get_models
     31    app_models = get_models(app)
     32    app_label = app_models[0]._meta.app_label
     33    return app_label
     34
    2935def _get_packages_insert(app_label):
    3036    from django.db import backend
    3137    return "INSERT INTO %s (%s, %s) VALUES ('%s', '%s');" % \
     
    338344    app_models = get_models(app)
    339345    app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql'))
    340346
     347    output.append(_get_packages_insert(_get_app_label(app)))
     348
    341349    for klass in app_models:
    342350        opts = klass._meta
    343351
     
    415423
    416424    pending_references = []
    417425
     426    initial_data = []
     427
    418428    for app in models.get_apps():
     429        is_new_app = True
    419430        model_list = models.get_models(app)
    420431        for model in model_list:
    421432            # Create the model's database table, if it doesn't already exist.
     
    420431        for model in model_list:
    421432            # Create the model's database table, if it doesn't already exist.
    422433            if model._meta.db_table in table_list:
     434                is_new_app = False
    423435                continue
    424436            field_metadata, table_metadata, references = sql_for_table(model)
    425437            pending_references.extend(references)
     
    429441            print "Creating table %s" % model._meta.db_table
    430442            cursor.execute(sql)
    431443
     444        if is_new_app:
     445            # This is a new app, get initial sql data
     446            initial_data.append((_get_app_label(app), get_sql_initial_data(app)))
     447
    432448        for model in model_list:
    433449            # Create the many-to-many join table, if it doesn't already exist.
    434450            for f in model._meta.many_to_many:
     
    454470                sql = '\n'.join(table_output)
    455471                print "Creating table %s" % f.m2m_db_table()
    456472                cursor.execute(sql)
     473               
     474    # Add initial sql data for the newly installed apps
     475    if len(initial_data) > 0:
     476        for label, sql_list in initial_data:
     477            print "Adding initial sql data for %s" % label
     478            for sql in sql_list:
     479                cursor.execute(sql)
    457480
    458481    # Create the pending references.
    459482    # Take care of any ALTER TABLE statements to add constraints
Back to Top