Opened 19 years ago

Closed 18 years ago

Last modified 18 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 Holovaty
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: no UI/UX: no

Description

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))

Change History (3)

comment:1 by Adrian Holovaty, 19 years ago

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

comment:2 by Adrian Holovaty, 18 years ago

Status: newassigned

comment:3 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: assignedclosed

This is a bit too much of a special case.

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