﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1813	[patch] Add a hook for loading SQL files that aren't tied to a particular model	anonymous	Adrian Holovaty	"hi.
I have a application which needs to insert data into tables of other applications. 
In my case it is to store defaults into preferences.

The app doesn't have any models (see #1812 as well), so I can't just add it onto a different model.

the following patch allows django to look for a unique SQL file for these cases.

{{{
Index: management.py
===================================================================
--- management.py       (revision 2864)
+++ management.py       (working copy)
@@ -342,11 +342,21 @@
 def get_sql_initial_data(app):
     ""Returns a list of the initial INSERT SQL statements for the given app.""
     from django.db.models import get_models
+    from django.conf import settings
     output = []
 
     app_models = get_models(app)
     app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql'))
 
+    app_sql_files = [ os.path.join(app_dir,""%s.sql"" % (app.__name__)),
+                      os.path.join(app_dir,""%s.%s.sql"" % (app.__name__, settings.DATABASE_ENGINE)) ]
+    for sql_file in app_sql_files:
+        if os.path.exists(sql_file):
+            fp = open(sql_file)
+            output.append(fp.read())
+            fp.close()
+
+
     for klass in app_models:
         output.extend(get_sql_initial_data_for_model(klass))
 }}}"	defect	closed	contrib.admin		normal	wontfix			Unreviewed	1	0	0	0	0	0
