Changes between Initial Version and Version 1 of Ticket #29564


Ignore:
Timestamp:
Jul 14, 2018, 5:27:02 PM (6 years ago)
Author:
Oleg Żero
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29564 – Description

    initial v1  
    1212}
    1313DATABASE_ROUTERS = ['myapplication.routers.AuthRouter']
     14...
    1415}}}
    1516
    1617Following your example [https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#topics-db-multi-db-routing],
    1718I created a router.py, in which I replicated your code.
     19However, being aware of the cross-database problem, my routers.py looks like this:
     20{{{
     21class AuthRouter(object):
     22    auth_related = (
     23            'auth',
     24            'admin',
     25            'contenttypes',
     26            'sessions',
     27    )
     28
     29    def db_for_read(self, model, **hints):
     30        if model._meta.app_label in self.auth_related:
     31            return 'users'
     32        return None
     33
     34    def db_for_write(self, model, **hints):
     35        if model._meta.app_label in self.auth_related:
     36            return 'users'
     37        return None
     38
     39    def allow_relation(self, obj1, obj2, **hints):
     40        if obj1._meta.app_label in self.auth_related or \
     41           obj2._meta.app_label in self.auth_related:
     42            return True
     43        return None
     44
     45    def allow_migrate(self, db, app_label, model_name=None, **hints):
     46        if app_label in self.auth_related:
     47            return db == 'users'
     48        return None
     49}}}
    1850
    1951Then:
Back to Top