Author: jbronn
Date: 2007-07-25 20:44:09 -0500 (Wed, 25 Jul 2007)
New Revision: 5759

Modified:
   django/branches/gis/django/core/management.py
   django/branches/gis/django/db/models/base.py
   django/branches/gis/django/db/models/fields/__init__.py
Log:
gis: added get_placeholder() routine for the Field class; fixed bug in 
management _post_create_sql() hook and added _post_delete_sql() hook.


Modified: django/branches/gis/django/core/management.py
===================================================================
--- django/branches/gis/django/core/management.py       2007-07-25 03:18:17 UTC 
(rev 5758)
+++ django/branches/gis/django/core/management.py       2007-07-26 01:44:09 UTC 
(rev 5759)
@@ -382,6 +382,12 @@
                 if hasattr(backend, 'get_drop_sequence'):
                     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
 
@@ -417,6 +423,11 @@
     app_dir = 
os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__),
 'sql'))
     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,
     # so split into separate statements.
     statements = re.compile(r";[ \t]*$", re.M)
@@ -434,10 +445,6 @@
                     output.append(statement + ";")
             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
 
 def get_custom_sql(app):

Modified: django/branches/gis/django/db/models/base.py
===================================================================
--- django/branches/gis/django/db/models/base.py        2007-07-25 03:18:17 UTC 
(rev 5758)
+++ django/branches/gis/django/db/models/base.py        2007-07-26 01:44:09 UTC 
(rev 5759)
@@ -227,11 +227,12 @@
         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)]
             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 pk_set:
                 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)]
-            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:
                 field_names.append(backend.quote_name('_order'))
                 # TODO: This assumes the database supports subqueries.

Modified: django/branches/gis/django/db/models/fields/__init__.py
===================================================================
--- django/branches/gis/django/db/models/fields/__init__.py     2007-07-25 
03:18:17 UTC (rev 5758)
+++ django/branches/gis/django/db/models/fields/__init__.py     2007-07-26 
01:44:09 UTC (rev 5759)
@@ -216,6 +216,10 @@
         """
         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):
         params = {'validator_list': self.validator_list[:]}
         if self.maxlength and not self.choices: # Don't give SelectFields a 
maxlength parameter.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to