1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

[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
This commit is contained in:
Jason Pellerin 2006-07-03 20:57:52 +00:00
parent f194f74aa6
commit 062733a946
2 changed files with 23 additions and 8 deletions

View File

@ -561,8 +561,9 @@ diffsettings.args = ""
def install(app): def install(app):
"Executes the equivalent of 'get_sql_all' in the current database." "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] app_name = app.__name__.split('.')[-2]
disable_termcolors() disable_termcolors()
@ -570,12 +571,13 @@ def install(app):
# First, try validating the models. # First, try validating the models.
_check_for_validation_errors(app) _check_for_validation_errors(app)
sql_list = get_sql_all(app)
try: try:
cursor = connection.cursor() pending = []
for sql in sql_list: for model in models.get_models(app):
cursor.execute(sql) pending.extend(model._default_manager.install(True))
if pending:
for statement in pending:
statement.execute()
except Exception, e: except Exception, e:
sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons: sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons:
* The database isn't running or isn't configured correctly. * The database isn't running or isn't configured correctly.

View File

@ -92,5 +92,18 @@ True
False False
>>> Artist._meta.connection.settings == Vehicle._meta.connection.settings >>> Artist._meta.connection.settings == Vehicle._meta.connection.settings
False 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)
[<Artist: Paul Klee>]
>>> artists[0]._meta.connection.settings == connections['django_test_db_a'].settings
True
""" """