1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

gis: added get_placeholder() routine for the Field class; fixed bug in management _post_create_sql() hook and added _post_delete_sql() hook.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5759 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2007-07-26 01:44:09 +00:00
parent add0689d56
commit 6be9797bee
3 changed files with 17 additions and 5 deletions

View File

@ -382,6 +382,12 @@ def get_sql_delete(app):
if hasattr(backend, 'get_drop_sequence'): if hasattr(backend, 'get_drop_sequence'):
output.append(backend.get_drop_sequence("%s_%s" % (model._meta.db_table, f.column))) output.append(backend.get_drop_sequence("%s_%s" % (model._meta.db_table, f.column)))
# Any post deletion needed? (e.g., DropGeometryColumn() in PostGIS)
for model in app_models:
opts = model._meta
for f in opts.fields:
if hasattr(f, '_post_delete_sql'):
output.append(f._post_delete_sql(style, model._meta.db_table))
app_label = app_models[0]._meta.app_label app_label = app_models[0]._meta.app_label
@ -417,6 +423,11 @@ def get_custom_sql_for_model(model):
app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql')) app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
output = [] output = []
# Post-creation SQL should come before any initial SQL data is loaded.
for f in opts.fields:
if hasattr(f, '_post_create_sql'):
output.append(f._post_create_sql(style, model._meta.db_table))
# Some backends can't execute more than one SQL statement at a time, # Some backends can't execute more than one SQL statement at a time,
# so split into separate statements. # so split into separate statements.
statements = re.compile(r";[ \t]*$", re.M) statements = re.compile(r";[ \t]*$", re.M)
@ -434,10 +445,6 @@ def get_custom_sql_for_model(model):
output.append(statement + ";") output.append(statement + ";")
fp.close() fp.close()
for f in opts.fields:
if hasattr(f, '_post_create_sql'):
output.append(f._post_create_sql(style, model._meta.db_table))
return output return output
def get_custom_sql(app): def get_custom_sql(app):

View File

@ -227,11 +227,12 @@ class Model(object):
if not pk_set or not record_exists: if not pk_set or not record_exists:
field_names = [backend.quote_name(f.column) for f in self._meta.fields if not isinstance(f, AutoField)] field_names = [backend.quote_name(f.column) for f in self._meta.fields if not isinstance(f, AutoField)]
db_values = [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)] db_values = [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)]
placeholders = [f.get_placeholder(f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)]
# If the PK has been manually set, respect that. # If the PK has been manually set, respect that.
if pk_set: if pk_set:
field_names += [f.column for f in self._meta.fields if isinstance(f, AutoField)] field_names += [f.column for f in self._meta.fields if isinstance(f, AutoField)]
db_values += [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if isinstance(f, AutoField)] db_values += [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if isinstance(f, AutoField)]
placeholders = ['%s'] * len(field_names) placeholders += [f.get_placeholder(f.pre_save(self, True)) for f in self._meta.fields if isinstance(f, AutoField)]
if self._meta.order_with_respect_to: if self._meta.order_with_respect_to:
field_names.append(backend.quote_name('_order')) field_names.append(backend.quote_name('_order'))
# TODO: This assumes the database supports subqueries. # TODO: This assumes the database supports subqueries.

View File

@ -216,6 +216,10 @@ class Field(object):
""" """
return [name_prefix + self.name] return [name_prefix + self.name]
def get_placeholder(self, value):
"Returns the placeholder substitution string for the field with the given value."
return '%s'
def prepare_field_objs_and_params(self, manipulator, name_prefix): def prepare_field_objs_and_params(self, manipulator, name_prefix):
params = {'validator_list': self.validator_list[:]} params = {'validator_list': self.validator_list[:]}
if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter. if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.