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:
parent
f194f74aa6
commit
062733a946
@ -561,7 +561,8 @@ 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]
|
||||
|
||||
@ -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.
|
||||
|
@ -93,4 +93,17 @@ 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)
|
||||
[<Artist: Paul Klee>]
|
||||
>>> artists[0]._meta.connection.settings == connections['django_test_db_a'].settings
|
||||
True
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user