Ticket #825: south.diff

File south.diff, 1.9 KB (added by matt@…, 3 years ago)

Patch to allow for '--edit' flag on schemamigration command.

  • south/management/commands/schemamigration.py

    diff --git a/south/management/commands/schemamigration.py b/south/management/commands/schemamigration.py
    a b class Command(DataCommand): 
    3939            help='Attempt to automatically detect differences from the last migration.'), 
    4040        make_option('--empty', action='store_true', dest='empty', default=False, 
    4141            help='Make a blank migration.'), 
     42        make_option('--edit', action='store_true', dest='edit_migration', default=False, 
     43            help='Edit the file after creating it.'), 
    4244    ) 
    4345    help = "Creates a new template schema migration for the given app" 
    4446    usage_str = "Usage: ./manage.py schemamigration appname migrationname [--empty] [--initial] [--auto] [--add-model ModelName] [--add-field ModelName.field_name] [--stdout]" 
    4547     
    46     def handle(self, app=None, name="", added_model_list=None, added_field_list=None, freeze_list=None, initial=False, auto=False, stdout=False, added_index_list=None, verbosity=1, empty=False, **options): 
     48    def handle(self, app=None, name="", added_model_list=None, added_field_list=None, freeze_list=None, initial=False, auto=False, stdout=False, added_index_list=None, verbosity=1, empty=False, edit_migration=False, **options): 
    4749         
    4850        # Any supposed lists that are None become empty lists 
    4951        added_model_list = added_model_list or [] 
    class Command(DataCommand): 
    170172                print >>sys.stderr, "Created %s. You must now edit this migration and add the code for each direction." % new_filename 
    171173            else: 
    172174                print >>sys.stderr, "Created %s. You can now apply this migration with: ./manage.py migrate %s" % (new_filename, app) 
     175            if edit_migration: 
     176                os.system('%s %s' % (os.environ['EDITOR'], os.path.join(migrations.migrations_dir(), new_filename))) 
    173177 
    174178 
    175179MIGRATION_TEMPLATE = """# encoding: utf-8