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):
|
147 | 147 | |
148 | 148 | def custom_sql_for_model(model, style, connection): |
149 | 149 | 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 | |
151 | 162 | output = [] |
152 | 163 | |
153 | 164 | # Post-creation SQL should come before any initial SQL data is loaded. |
… |
… |
def custom_sql_for_model(model, style, connection):
|
164 | 175 | |
165 | 176 | # Find custom SQL, if it's available. |
166 | 177 | 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())) |
169 | 182 | for sql_file in sql_files: |
170 | 183 | if os.path.exists(sql_file): |
171 | 184 | fp = open(sql_file, 'U') |