This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2012-02-02 03:47:44 +01:00

32 lines
1.1 KiB
Python

def is_radius_model(model):
return hasattr(model, 'connection_name')
class Router(object):
"""
A router to point database operations on models to the right db.
Using the attribute connection_name referring to the
DATABASES-label in settings.py.
Ref: https://docs.djangoproject.com/en/dev/topics/db/multi-db/
"""
def allow_syncdb(self, db, model):
"""Do not create tables on the default db for models on $./manage.py sync,
but this function maybe used know which db a model is on"""
if is_radius_model(model):
return db == model.connection_name
return db == 'default'
def db_for_read(self, model, **hints):
"Point all operations on models connection_name to db=connection_name"
if is_radius_model(model):
return model.connection_name
return None
def db_for_write(self, model, **hints):
"Point all operations on models connection_name to db=connection_name"
if is_radius_model(model):
return model.connection_name
return None