Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 authored July 03, 2006
16  django/core/management.py
@@ -561,8 +561,9 @@ def diffsettings():
561 561
 
562 562
 def install(app):
563 563
     "Executes the equivalent of 'get_sql_all' in the current database."
564  
-    from django.db import connection, transaction
565  
-
  564
+    from django.db import connection, models, transaction
  565
+    import sys
  566
+    
566 567
     app_name = app.__name__.split('.')[-2]
567 568
 
568 569
     disable_termcolors()
@@ -570,12 +571,13 @@ def install(app):
570 571
     # First, try validating the models.
571 572
     _check_for_validation_errors(app)
572 573
 
573  
-    sql_list = get_sql_all(app)
574  
-
575 574
     try:
576  
-        cursor = connection.cursor()
577  
-        for sql in sql_list:
578  
-            cursor.execute(sql)
  575
+        pending = []
  576
+        for model in models.get_models(app):
  577
+            pending.extend(model._default_manager.install(True))
  578
+        if pending:
  579
+            for statement in pending:
  580
+                statement.execute()
579 581
     except Exception, e:
580 582
         sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons:
581 583
   * The database isn't running or isn't configured correctly.
15  tests/modeltests/multiple_databases/models.py
@@ -92,5 +92,18 @@ def __str__(self):
92 92
 False
93 93
 >>> Artist._meta.connection.settings == Vehicle._meta.connection.settings
94 94
 False
95  
-    
  95
+
  96
+# Managers use their models' connections
  97
+
  98
+>>> a = Artist(name="Paul Klee", alive=False)
  99
+>>> a.save()
  100
+>>> w = Widget(code='100x2r', weight=1000)
  101
+>>> w.save()
  102
+>>> v = Vehicle(make='Chevy', model='Camaro', year='1966')
  103
+>>> v.save()
  104
+>>> artists = Artist.objects.all()
  105
+>>> list(artists)
  106
+[<Artist: Paul Klee>]
  107
+>>> artists[0]._meta.connection.settings == connections['django_test_db_a'].settings
  108
+True
96 109
 """

0 notes on commit 062733a

Please sign in to comment.
Something went wrong with that request. Please try again.