Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
  • Loading branch information...
commit 062733a946b360eead2355ab9c1a21ea14c22e5f 1 parent f194f74
JP jpellerin authored
16 django/core/management.py
View
@@ -561,8 +561,9 @@ def diffsettings():
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.
15 tests/modeltests/multiple_databases/models.py
View
@@ -92,5 +92,18 @@ def __str__(self):
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
"""
Please sign in to comment.
Something went wrong with that request. Please try again.