From Django 1.2, you can specify the class of the router for routing queries to various databases ( https://docs.djangoproject.com/en/dev/topics/db/multi-db/ ).
To use one bit for reading and one for writing, you can define the Router class as follows:
Class MyRouter(object): def db_for_read(self, model, **hints): return 'default_readonly' def db_for_write(self, model, **hints): return 'default' def allow_syncdb(self, db, model): return db == 'default'
And put it in your settings.py
DATABASE_ROUTERS = ['path.to.MyRouter']
This works for me until I use select_for_update (), which is considered a read operation but requires write access to the database. The only workaround I have found so far is to override select_for_update in the manager class in a similar way:
class MyManager(Manager): def select_for_update(self, *args, **kwargs): return super(MyManager, self).using('default').select_for_update(*args, **kwargs)
Oberix
source share