From 408c10e541440b078ccf5d6fcb3f344b7a94d048 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Sat, 8 Sep 2012 16:08:01 -0400 Subject: [PATCH] Untabify multi-db docs. --- docs/topics/db/multi-db.txt | 108 ++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt index ef9c5a2648..82218692d8 100644 --- a/docs/topics/db/multi-db.txt +++ b/docs/topics/db/multi-db.txt @@ -242,41 +242,41 @@ send queries for the ``auth`` app to ``auth_db``:: A router to control all database operations on models in the auth application. """ - def db_for_read(self, model, **hints): - """ - Attempts to read auth models go to auth_db. - """ - if model._meta.app_label == 'auth': - return 'auth_db' - return None + def db_for_read(self, model, **hints): + """ + Attempts to read auth models go to auth_db. + """ + if model._meta.app_label == 'auth': + return 'auth_db' + return None - def db_for_write(self, model, **hints): - """ - Attempts to write auth models go to auth_db. - """ - if model._meta.app_label == 'auth': - return 'auth_db' - return Non + def db_for_write(self, model, **hints): + """ + Attempts to write auth models go to auth_db. + """ + if model._meta.app_label == 'auth': + return 'auth_db' + return Non - def allow_relation(self, obj1, obj2, **hints): - """ - Allow relations if a model in the auth app is involved. - """ - if obj1._meta.app_label == 'auth' or \ + def allow_relation(self, obj1, obj2, **hints): + """ + Allow relations if a model in the auth app is involved. + """ + if obj1._meta.app_label == 'auth' or \ obj2._meta.app_label == 'auth': - return True - return None + return True + return None - def allow_syncdb(self, db, model): - """ - Make sure the auth app only appears in the 'auth_db' - database. - """ - if db == 'auth_db': - return model._meta.app_label == 'auth' - elif model._meta.app_label == 'auth': - return False - return None + def allow_syncdb(self, db, model): + """ + Make sure the auth app only appears in the 'auth_db' + database. + """ + if db == 'auth_db': + return model._meta.app_label == 'auth' + elif model._meta.app_label == 'auth': + return False + return None And we also want a router that sends all other apps to the master/slave configuration, and randomly chooses a slave to read @@ -286,32 +286,32 @@ from:: class MasterSlaveRouter(object): def db_for_read(self, model, **hints): - """ - Reads go to a randomly-chosen slave. - """ - return random.choice(['slave1', 'slave2']) + """ + Reads go to a randomly-chosen slave. + """ + return random.choice(['slave1', 'slave2']) - def db_for_write(self, model, **hints): - """ - Writes always go to master. - """ - return 'master' + def db_for_write(self, model, **hints): + """ + Writes always go to master. + """ + return 'master' - def allow_relation(self, obj1, obj2, **hints): - """ - Relations between objects are allowed if both objects are - in the master/slave pool. - """ - db_list = ('master', 'slave1', 'slave2') - if obj1.state.db in db_list and obj2.state.db in db_list: - return True - return None + def allow_relation(self, obj1, obj2, **hints): + """ + Relations between objects are allowed if both objects are + in the master/slave pool. + """ + db_list = ('master', 'slave1', 'slave2') + if obj1.state.db in db_list and obj2.state.db in db_list: + return True + return None - def allow_syncdb(self, db, model): - """ - All non-auth models end up in this pool. - """ - return True + def allow_syncdb(self, db, model): + """ + All non-auth models end up in this pool. + """ + return True Finally, in the settings file, we add the following (substituting ``path.to.`` with the actual python path to the module(s) where the