Ticket #15519: patch-15519.diff

File patch-15519.diff, 1.6 KB (added by Vlastimil Zíma, 14 years ago)
  • django/core/management/sql.py

    diff --git a/django/core/management/sql.py b/django/core/management/sql.py
    index 429f470..4435b9a 100644
    a b def sql_all(app, style, connection):  
    147147
    148148def custom_sql_for_model(model, style, connection):
    149149    opts = model._meta
    150     app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
     150
     151    app = models.get_app(model._meta.app_label)
     152    app_dirs = []
     153    if hasattr(app, '__path__'):
     154        # It's a 'models/' subpackage
     155        for path in app.__path__:
     156            path = os.path.normpath(os.path.join(path, 'sql'))
     157            app_dirs.append(path)
     158    else:
     159        # It's a models.py module
     160        app_dirs.append(os.path.normpath(os.path.join(os.path.dirname(app.__file__))))
     161
    151162    output = []
    152163
    153164    # Post-creation SQL should come before any initial SQL data is loaded.
    def custom_sql_for_model(model, style, connection):  
    164175
    165176    # Find custom SQL, if it's available.
    166177    backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
    167     sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)),
    168                  os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
     178    sql_files = []
     179    for app_dir in app_dirs:
     180        sql_files.append(os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)))
     181        sql_files.append(os.path.join(app_dir, "%s.sql" % opts.object_name.lower()))
    169182    for sql_file in sql_files:
    170183        if os.path.exists(sql_file):
    171184            fp = open(sql_file, 'U')
Back to Top