]> git.parisson.com Git - mezzo.git/commitdiff
add router
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 31 Mar 2016 16:23:36 +0000 (18:23 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 31 Mar 2016 16:23:36 +0000 (18:23 +0200)
app/sandbox/routers.py [new file with mode: 0644]

diff --git a/app/sandbox/routers.py b/app/sandbox/routers.py
new file mode 100644 (file)
index 0000000..7766b6d
--- /dev/null
@@ -0,0 +1,35 @@
+
+
+class Router(object):
+    """
+    A router to control all database operations between the 2 apps
+    """
+    def db_for_read(self, model, **hints):
+        if model._meta.app_label == 'eve':
+            return 'eve'
+        if model._meta.app_label == 'presta':
+            return 'presta'
+        return None
+
+    def db_for_write(self, model, **hints):
+        if model._meta.app_label == 'eve':
+            return 'eve'
+        if model._meta.app_label == 'presta':
+            return 'presta'
+        return None
+
+    def allow_relation(self, obj1, obj2, **hints):
+        if obj1._meta.app_label == 'eve' or \
+           obj2._meta.app_label == 'eve':
+           return True
+        if obj1._meta.app_label == 'presta' or \
+           obj2._meta.app_label == 'presta':
+           return True
+        return None
+
+    def allow_migrate(self, db, app_label, model=None, **hints):
+        if app_label == 'eve':
+            return db == 'eve'
+        if app_label == 'presta':
+            return db == 'presta'
+        return None