Ticket #7589: gis_post_create_sql.diff
File gis_post_create_sql.diff, 3.1 KB (added by , 16 years ago) |
---|
-
commands/sqlcustom.py
7 7 8 8 def handle_app(self, app, **options): 9 9 from django.core.management.sql import sql_custom 10 return u'\n'.join(sql_custom(app )).encode('utf-8')10 return u'\n'.join(sql_custom(app, self.style)).encode('utf-8') -
commands/syncdb.py
112 112 app_name = app.__name__.split('.')[-2] 113 113 for model in models.get_models(app): 114 114 if model in created_models: 115 custom_sql = custom_sql_for_model(model )115 custom_sql = custom_sql_for_model(model, self.style) 116 116 if custom_sql: 117 117 if verbosity >= 1: 118 118 print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name) -
sql.py
219 219 statements = connection.ops.sql_flush(style, tables, sequence_list()) 220 220 return statements 221 221 222 def sql_custom(app ):222 def sql_custom(app, style): 223 223 "Returns a list of the custom table modifying SQL statements for the given app." 224 224 from django.db.models import get_models 225 225 output = [] … … 228 228 app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql')) 229 229 230 230 for model in app_models: 231 output.extend(custom_sql_for_model(model ))231 output.extend(custom_sql_for_model(model, style)) 232 232 233 233 return output 234 234 … … 242 242 243 243 def sql_all(app, style): 244 244 "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module." 245 return sql_create(app, style) + sql_custom(app ) + sql_indexes(app, style)245 return sql_create(app, style) + sql_custom(app, style) + sql_indexes(app, style) 246 246 247 247 def sql_model_create(model, style, known_models=set()): 248 248 """ … … 426 426 427 427 return final_output 428 428 429 def custom_sql_for_model(model ):429 def custom_sql_for_model(model, style): 430 430 from django.db import models 431 431 from django.conf import settings 432 432 … … 434 434 app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql')) 435 435 output = [] 436 436 437 # Post-creation SQL should come before any initial SQL data is loaded. 438 # However, this should not be done for fields that are part of a 439 # a parent model (via model inheritance). 440 nm = opts.init_name_map() 441 post_sql_fields = [f for f in opts.fields if nm[f.name][1] is None and hasattr(f, '_post_create_sql')] 442 for f in post_sql_fields: 443 output.extend(f._post_create_sql(style, model._meta.db_table)) 444 437 445 # Some backends can't execute more than one SQL statement at a time, 438 446 # so split into separate statements. 439 447 statements = re.compile(r";[ \t]*$", re.M)