Changeset 7568
- Timestamp:
- 05/30/08 20:01:17 (6 months ago)
- Files:
-
- django/trunk/django/core/management/commands/syncdb.py (modified) (2 diffs)
- django/trunk/django/core/management/sql.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/commands/syncdb.py
r7294 r7568 22 22 from django.db import connection, transaction, models 23 23 from django.conf import settings 24 from django.core.management.sql import table_ list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal24 from django.core.management.sql import table_names, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal 25 25 26 26 verbosity = int(options.get('verbosity', 1)) … … 46 46 # Get a list of all existing database tables, so we know what needs to 47 47 # be added. 48 tables = [table_name_converter(name) for name in table_ list()]48 tables = [table_name_converter(name) for name in table_names()] 49 49 50 50 # Get a list of already installed *models* so that references work right. django/trunk/django/core/management/sql.py
r7477 r7568 8 8 from sets import Set as set # Python 2.3 fallback 9 9 10 def table_ list():10 def table_names(): 11 11 "Returns a list of all table names that exist in the database." 12 12 from django.db import connection, get_introspection_module 13 13 cursor = connection.cursor() 14 return get_introspection_module().get_table_list(cursor)15 16 def django_table_ list(only_existing=False):14 return set(get_introspection_module().get_table_list(cursor)) 15 16 def django_table_names(only_existing=False): 17 17 """ 18 18 Returns a list of all table names that have associated Django models and … … 23 23 """ 24 24 from django.db import models 25 tables = []25 tables = set() 26 26 for app in models.get_apps(): 27 27 for model in models.get_models(app): 28 tables.a ppend(model._meta.db_table)29 tables. extend([f.m2m_db_table() for f in model._meta.local_many_to_many])28 tables.add(model._meta.db_table) 29 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many]) 30 30 if only_existing: 31 existing = table_list() 32 tables = [t for t in tables if t in existing] 31 tables = [t for t in tables if t in table_names()] 33 32 return tables 34 33 … … 83 82 app_models = models.get_models(app) 84 83 final_output = [] 85 known_models = set([model for model in installed_models(table_ list()) if model not in app_models])84 known_models = set([model for model in installed_models(table_names()) if model not in app_models]) 86 85 pending_references = {} 87 86 … … 215 214 from django.db import connection 216 215 if only_django: 217 tables = django_table_ list()216 tables = django_table_names() 218 217 else: 219 tables = table_ list()218 tables = table_names() 220 219 statements = connection.ops.sql_flush(style, tables, sequence_list()) 221 220 return statements
