Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#1813 closed defect (wontfix)

[patch] Add a hook for loading SQL files that aren't tied to a particular model

Reported by: anonymous Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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.

---       (revision 2864)
+++       (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.close()
     for klass in app_models:

Change History (3)

comment:1 Changed 10 years ago by adrian

  • Summary changed from [patch] sqlinitialdata should be able to load non-model SQL to [patch] Add a hook for loading SQL files that aren't tied to a particular model

comment:2 Changed 10 years ago by adrian

  • Status changed from new to assigned

comment:3 Changed 10 years ago by adrian

  • Resolution set to wontfix
  • Status changed from assigned to closed

This is a bit too much of a special case.

Note: See TracTickets for help on using tickets.
Back to Top