old_contents: """Database apps router
  
  This module has been shamelessly copy-pasted from
  http://diegobz.net/2011/02/10/django-database-router-using-settings/
  and then improved a little then
  
  Thanks to answerers @ http://stackoverflow.com/a/18548287/595220
  """
  
  from django.conf import settings
  
  
  class DatabaseAppsRouter(object):
      """
      A router to control all database operations on models for different
      databases.
  
      In case an app is not set in settings.DATABASE_APPS_MAPPING, the router
      will fallback to the `default` database.
  
      Settings example:
  
      DATABASE_APPS_MAPPING = {'app1': 'db1', 'app2': 'db2'}
      """
  
      def db_for_read(self, model, **hints):
          """"Point all read operations to the specific database."""
          return settings.DATABASE_APPS_MAPPING.get(model._meta.db_route)
  
      def db_for_write(self, model, **hints):
          """Point all write operations to the specific database."""
          return settings.DATABASE_APPS_MAPPING.get(model._meta.db_route)
  
      def allow_relation(self, obj1, obj2, **hints):
          """Allow any relation between apps that use the same database."""
          try:
              db_obj1 = settings.DATABASE_APPS_MAPPING[obj1._meta.db_route]
              db_obj2 = settings.DATABASE_APPS_MAPPING[obj2._meta.db_route]
          except KeyError:
              return None
          else:
              return db_obj1 == db_obj2
  
      def allow_syncdb(self, db, model):
          """Make sure that apps only appear in the related database."""
          if db in settings.DATABASE_APPS_MAPPING.values():
              return settings.DATABASE_APPS_MAPPING.get(model._meta.db_route) == db
          elif model._meta.db_route in settings.DATABASE_APPS_MAPPING:
              return False
          return None
  
new_contents: """Database apps router
  
  This module has been shamelessly copy-pasted from
  http://diegobz.net/2011/02/10/django-database-router-using-settings/
  and then improved a little then
  
  Thanks to answerers @ http://stackoverflow.com/a/18548287/595220
  """
  
  from django.conf import settings
  
  
  class DatabaseAppsRouter(object):
      """
      A router to control all database operations on models for different
      databases.
  
      In case an app is not set in settings.DATABASE_APPS_MAPPING, the router
      will fallback to the `default` database.
  
      Settings example:
  
      DATABASE_APPS_MAPPING = {'app1': 'db1', 'app2': 'db2'}
      """
  
      def db_for_read(self, model, **hints):
          """"Point all read operations to the specific database."""
  
          return settings.DATABASE_APPS_MAPPING.get(getattr(model._meta, 'db_route', None), 'default')
  
      def db_for_write(self, model, **hints):
          """Point all write operations to the specific database."""
  
          return settings.DATABASE_APPS_MAPPING.get(getattr(model._meta, 'db_route', None), 'default')
  
      def allow_relation(self, obj1, obj2, **hints):
          """Allow any relation between apps that use the same database."""
  
          db_obj1 = settings.DATABASE_APPS_MAPPING.get(getattr(obj1._meta, 'db_route', None), 'default')
          db_obj2 = settings.DATABASE_APPS_MAPPING.get(getattr(obj2._meta, 'db_route', None), 'default')
          return db_obj1 == db_obj2
  
      def allow_syncdb(self, db, model):
          """Make sure that apps only appear in the related database."""
  
          if db in settings.DATABASE_APPS_MAPPING.values() or db == 'default':
              return settings.DATABASE_APPS_MAPPING.get(getattr(model._meta.db_route, 'db_route', None), 'default') == db
          elif model._meta.db_route in settings.DATABASE_APPS_MAPPING:
              return False
          return None
  
subject: Fix db router