Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

gis: Fixed `_post_create_sql` hook to not generate additional SQL for…

… fields belonging to a parent model via model inheritance. Thanks, robotika.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7513 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 579c9d45679dd8f6e9d83cfd75d09fae0595dedf 1 parent 57c700d
Justin Bronn authored May 02, 2008

Showing 1 changed file with 6 additions and 3 deletions. Show diff stats Hide diff stats

  1. 9  django/core/management/sql.py
9  django/core/management/sql.py
@@ -436,9 +436,12 @@ def custom_sql_for_model(model, style):
436 436
     output = []
437 437
 
438 438
     # Post-creation SQL should come before any initial SQL data is loaded.
439  
-    for f in opts.fields:
440  
-        if hasattr(f, '_post_create_sql'):
441  
-            output.extend(f._post_create_sql(style, model._meta.db_table))
  439
+    # However, this should not be done for fields that are part of a 
  440
+    # a parent model (via model inheritance).
  441
+    nm = opts.init_name_map()
  442
+    post_sql_fields = [f for f in opts.fields if nm[f.name][1] is None and hasattr(f, '_post_create_sql')]
  443
+    for f in post_sql_fields:
  444
+        output.extend(f._post_create_sql(style, model._meta.db_table))
442 445
 
443 446
     # Some backends can't execute more than one SQL statement at a time,
444 447
     # so split into separate statements.

0 notes on commit 579c9d4

Please sign in to comment.
Something went wrong with that request. Please try again.