From 062733a946b360eead2355ab9c1a21ea14c22e5f Mon Sep 17 00:00:00 2001 From: Jason Pellerin Date: Mon, 3 Jul 2006 20:57:52 +0000 Subject: [PATCH] [multi-db] Began integrating Manager schema manipulation methods into django.core.management. Updated multiple db models test to include operations on installed models. git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3267 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management.py | 16 +++++++++------- tests/modeltests/multiple_databases/models.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/django/core/management.py b/django/core/management.py index ea210af88f..47793e8306 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -561,8 +561,9 @@ diffsettings.args = "" def install(app): "Executes the equivalent of 'get_sql_all' in the current database." - from django.db import connection, transaction - + from django.db import connection, models, transaction + import sys + app_name = app.__name__.split('.')[-2] disable_termcolors() @@ -570,12 +571,13 @@ def install(app): # First, try validating the models. _check_for_validation_errors(app) - sql_list = get_sql_all(app) - try: - cursor = connection.cursor() - for sql in sql_list: - cursor.execute(sql) + pending = [] + for model in models.get_models(app): + pending.extend(model._default_manager.install(True)) + if pending: + for statement in pending: + statement.execute() except Exception, e: sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons: * The database isn't running or isn't configured correctly. diff --git a/tests/modeltests/multiple_databases/models.py b/tests/modeltests/multiple_databases/models.py index 3c89c83e75..11915dee47 100644 --- a/tests/modeltests/multiple_databases/models.py +++ b/tests/modeltests/multiple_databases/models.py @@ -92,5 +92,18 @@ True False >>> Artist._meta.connection.settings == Vehicle._meta.connection.settings False - + +# Managers use their models' connections + +>>> a = Artist(name="Paul Klee", alive=False) +>>> a.save() +>>> w = Widget(code='100x2r', weight=1000) +>>> w.save() +>>> v = Vehicle(make='Chevy', model='Camaro', year='1966') +>>> v.save() +>>> artists = Artist.objects.all() +>>> list(artists) +[] +>>> artists[0]._meta.connection.settings == connections['django_test_db_a'].settings +True """