Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed get_migratable_models to use an app config.

  • Loading branch information...
commit 856aaaf2b15228bd5babbe44654c3c1ca39e8fd7 1 parent 1d4bcb8
@aaugustin aaugustin authored
View
2  django/core/management/commands/flush.py
@@ -94,5 +94,5 @@ def emit_post_migrate(verbosity, interactive, database):
# respond as if the database had been migrated from scratch.
all_models = []
for app_config in apps.get_app_configs(only_with_models_module=True):
- all_models.extend(router.get_migratable_models(app_config.models_module, database, include_auto_created=True))
+ all_models.extend(router.get_migratable_models(app_config, database, include_auto_created=True))
emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
View
2  django/core/management/commands/migrate.py
@@ -180,7 +180,7 @@ def sync_apps(self, connection, app_labels):
# Build the manifest of apps and models that are to be synchronized
all_models = [
(app_config.label,
- router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True))
+ router.get_migratable_models(app_config, connection.alias, include_auto_created=True))
for app_config in apps.get_app_configs(only_with_models_module=True)
if app_config.label in app_labels
]
View
10 django/core/management/sql.py
@@ -31,7 +31,7 @@ def sql_create(app_config, style, connection):
known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models)
pending_references = {}
- for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
+ for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
output, references = connection.creation.sql_create_model(model, style, known_models)
final_output.extend(output)
for refto, refs in references.items():
@@ -78,7 +78,7 @@ def sql_delete(app_config, style, connection):
to_delete = set()
references_to_delete = {}
- app_models = router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True)
+ app_models = router.get_migratable_models(app_config, connection.alias, include_auto_created=True)
for model in app_models:
if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
# The table exists, so it needs to be dropped
@@ -122,7 +122,7 @@ def sql_custom(app_config, style, connection):
"Returns a list of the custom table modifying SQL statements for the given app."
output = []
- app_models = router.get_migratable_models(app_config.models_module, connection.alias)
+ app_models = router.get_migratable_models(app_config, connection.alias)
for model in app_models:
output.extend(custom_sql_for_model(model, style, connection))
@@ -133,7 +133,7 @@ def sql_custom(app_config, style, connection):
def sql_indexes(app_config, style, connection):
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
output = []
- for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
+ for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
output.extend(connection.creation.sql_indexes_for_model(model, style))
return output
@@ -141,7 +141,7 @@ def sql_indexes(app_config, style, connection):
def sql_destroy_indexes(app_config, style, connection):
"Returns a list of the DROP INDEX SQL statements for all models in the given app."
output = []
- for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
+ for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
output.extend(connection.creation.sql_destroy_indexes_for_model(model, style))
return output
View
6 django/db/backends/__init__.py
@@ -1272,7 +1272,7 @@ def django_table_names(self, only_existing=False):
from django.db import router
tables = set()
for app_config in apps.get_app_configs(only_with_models_module=True):
- for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
+ for model in router.get_migratable_models(app_config, self.connection.alias):
if not model._meta.managed:
continue
tables.add(model._meta.db_table)
@@ -1293,7 +1293,7 @@ def installed_models(self, tables):
from django.db import router
all_models = []
for app_config in apps.get_app_configs(only_with_models_module=True):
- all_models.extend(router.get_migratable_models(app_config.models_module, self.connection.alias))
+ all_models.extend(router.get_migratable_models(app_config, self.connection.alias))
tables = list(map(self.table_name_converter, tables))
return set([
m for m in all_models
@@ -1308,7 +1308,7 @@ def sequence_list(self):
sequence_list = []
for app_config in apps.get_app_configs(only_with_models_module=True):
- for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
+ for model in router.get_migratable_models(app_config, self.connection.alias):
if not model._meta.managed:
continue
if model._meta.swapped:
View
7 django/db/utils.py
@@ -278,10 +278,9 @@ def allow_migrate(self, db, model):
return allow
return True
- def get_migratable_models(self, app, db, include_auto_created=False):
+ def get_migratable_models(self, app_config, db, include_auto_created=False):
"""
Return app models allowed to be synchronized on provided db.
"""
- from django.apps import apps
- return [model for model in apps.get_models(app, include_auto_created=include_auto_created)
- if self.allow_migrate(db, model)]
+ models = app_config.get_models(include_auto_created=include_auto_created)
+ return [model for model in models if self.allow_migrate(db, model)]
Please sign in to comment.
Something went wrong with that request. Please try again.