Django

Code

Changeset 8133

Show
Ignore:
Timestamp:
07/29/08 00:53:44 (4 months ago)
Author:
mtredinnick
Message:

Fixed #7589 -- Added a way for post-table-creation SQL modifications to be done for custom fields (needed by geo-django, but useful in other situations, too).

Patch from Justin Bronn.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/commands/sqlcustom.py

    r7706 r8133  
    88    def handle_app(self, app, **options): 
    99        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') 
  • django/trunk/django/core/management/commands/syncdb.py

    r7891 r8133  
    117117            for model in models.get_models(app): 
    118118                if model in created_models: 
    119                     custom_sql = custom_sql_for_model(model
     119                    custom_sql = custom_sql_for_model(model, self.style
    120120                    if custom_sql: 
    121121                        if verbosity >= 1: 
  • django/trunk/django/core/management/sql.py

    r7790 r8133  
    220220    return statements 
    221221 
    222 def sql_custom(app): 
     222def sql_custom(app, style): 
    223223    "Returns a list of the custom table modifying SQL statements for the given app." 
    224224    from django.db.models import get_models 
     
    229229 
    230230    for model in app_models: 
    231         output.extend(custom_sql_for_model(model)) 
     231        output.extend(custom_sql_for_model(model, style)) 
    232232 
    233233    return output 
     
    243243def sql_all(app, style): 
    244244    "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) 
    246246 
    247247def sql_model_create(model, style, known_models=set()): 
     
    427427    return final_output 
    428428 
    429 def custom_sql_for_model(model): 
     429def custom_sql_for_model(model, style): 
    430430    from django.db import models 
    431431    from django.conf import settings 
     
    434434    app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql')) 
    435435    output = [] 
     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 a parent 
     439    # model (via model inheritance). 
     440    nm = opts.init_name_map() 
     441    post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')] 
     442    for f in post_sql_fields: 
     443        output.extend(f.post_create_sql(style, model._meta.db_table)) 
    436444 
    437445    # Some backends can't execute more than one SQL statement at a time,