diff --git a/moodlerouter.py b/moodlerouter.py new file mode 100644 index 0000000..41e4a9a --- /dev/null +++ b/moodlerouter.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +class MoodleRouter(object): + def db_for_read(self, model, **hints): + if model._meta.app_label == 'mdl': + return 'moodle' + return None + + def db_for_write(self, model, **hints): + if model._meta.app_label == 'mdl': + return 'moodle' + return None + + def allow_relation(self, obj1, obj2, **hints): + if obj1._meta.app_label == 'mdl' and obj2._meta.app_label == 'mdl': + return True + return None + + def allow_migrate(self, db, model): + if model._meta.app_label == 'mdl': + return False + return None \ No newline at end of file diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 6eb71b1..01d3857 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -37,6 +37,9 @@ TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) +# Database routers +DATABASE_ROUTERS = ['moodlerouter.MoodleRouter',] + # Application definition INSTALLED_APPS = ( diff --git a/sigi/settings/dev.py b/sigi/settings/dev.py index c9152e3..c5b35e9 100644 --- a/sigi/settings/dev.py +++ b/sigi/settings/dev.py @@ -8,6 +8,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'sigi.db'), + }, + 'moodle': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'moodle.db'), } }