Commits

Skirmantas Jurgaitis committed 8adec92

Allow to override shcemamigration template by extending command class

Comments (0)

Files changed (1)

south/management/commands/schemamigration.py

 from south.creator import changes, actions, freezer
 from south.management.commands.datamigration import Command as DataCommand
 
+
+MIGRATION_TEMPLATE = """# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+%(forwards)s
+
+    def backwards(self, orm):
+%(backwards)s
+
+    models = %(frozen_models)s
+
+    %(complete_apps)s"""
+
+
 class Command(DataCommand):
+    MIGRATION_TEMPLATE = MIGRATION_TEMPLATE
+
     option_list = DataCommand.option_list + (
         make_option('--add-model', action='append', dest='added_model_list', type='string',
             help='Generate a Create Table migration for the specified model.  Add multiple models to this migration with subsequent --add-model parameters.'),
         apps_to_freeze = self.calc_frozen_apps(migrations, freeze_list)
         
         # So, what's in this file, then?
-        file_contents = MIGRATION_TEMPLATE % {
+        file_contents = self.MIGRATION_TEMPLATE % {
             "forwards": "\n".join(forwards_actions or ["        pass"]),
             "backwards": "\n".join(backwards_actions or ["        pass"]),
             "frozen_models":  freezer.freeze_apps_to_string(apps_to_freeze),
                 print("%s %s. You must now edit this migration and add the code for each direction." % (verb, new_filename), file=sys.stderr)
             else:
                 print("%s %s. You can now apply this migration with: ./manage.py migrate %s" % (verb, new_filename, app), file=sys.stderr)
-
-
-MIGRATION_TEMPLATE = """# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
-    def forwards(self, orm):
-%(forwards)s
-
-    def backwards(self, orm):
-%(backwards)s
-
-    models = %(frozen_models)s
-
-    %(complete_apps)s"""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.