當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.DATABASE_ROUTERS屬性代碼示例

本文整理匯總了Python中django.conf.settings.DATABASE_ROUTERS屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.DATABASE_ROUTERS屬性的具體用法?Python settings.DATABASE_ROUTERS怎麽用?Python settings.DATABASE_ROUTERS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.DATABASE_ROUTERS屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def __init__(self, routers=None):
        """
        If routers is not specified, will default to settings.DATABASE_ROUTERS.
        """
        self._routers = routers 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:utils.py

示例2: routers

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def routers(self):
        if self._routers is None:
            self._routers = settings.DATABASE_ROUTERS
        routers = []
        for r in self._routers:
            if isinstance(r, six.string_types):
                router = import_string(r)()
            else:
                router = r
            routers.append(router)
        return routers 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:13,代碼來源:utils.py

示例3: __init__

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def __init__(self, routers=None):
        """
        If routers is not specified, default to settings.DATABASE_ROUTERS.
        """
        self._routers = routers 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:7,代碼來源:utils.py

示例4: routers

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def routers(self):
        if self._routers is None:
            self._routers = settings.DATABASE_ROUTERS
        routers = []
        for r in self._routers:
            if isinstance(r, str):
                router = import_string(r)()
            else:
                router = r
            routers.append(router)
        return routers 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:13,代碼來源:utils.py

示例5: ready

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def ready(self):
        from django.db import connection

        # Test for configuration recommendations. These are best practices,
        # they avoid hard to find bugs and unexpected behaviour.
        if not hasattr(settings, 'TENANT_APPS'):
            raise ImproperlyConfigured('TENANT_APPS setting not set')

        if not settings.TENANT_APPS:
            raise ImproperlyConfigured("TENANT_APPS is empty. "
                                       "Maybe you don't need this app?")

        if not hasattr(settings, 'TENANT_MODEL'):
            raise ImproperlyConfigured('TENANT_MODEL setting not set')

        if 'django_tenants.routers.TenantSyncRouter' not in settings.DATABASE_ROUTERS:
            raise ImproperlyConfigured("DATABASE_ROUTERS setting must contain "
                                       "'django_tenants.routers.TenantSyncRouter'.")

        if hasattr(settings, 'PG_EXTRA_SEARCH_PATHS'):
            if get_public_schema_name() in settings.PG_EXTRA_SEARCH_PATHS:
                raise ImproperlyConfigured(
                    "%s can not be included on PG_EXTRA_SEARCH_PATHS."
                    % get_public_schema_name())

            # make sure no tenant schema is in settings.PG_EXTRA_SEARCH_PATHS

            # first check that the model table is created
            model = get_tenant_model()
            c = connection.cursor()
            c.execute(
                'SELECT 1 FROM information_schema.tables WHERE table_name = %s;',
                [model._meta.db_table]
            )
            if c.fetchone():
                invalid_schemas = set(settings.PG_EXTRA_SEARCH_PATHS).intersection(
                    model.objects.all().values_list('schema_name', flat=True))
                if invalid_schemas:
                    raise ImproperlyConfigured(
                        "Do not include tenant schemas (%s) on PG_EXTRA_SEARCH_PATHS."
                        % list(invalid_schemas)) 
開發者ID:django-tenants,項目名稱:django-tenants,代碼行數:43,代碼來源:apps.py

示例6: _check_complementary_settings

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATABASE_ROUTERS [as 別名]
def _check_complementary_settings(self):
        if "django_pgschemas.routers.SyncRouter" not in settings.DATABASE_ROUTERS:
            raise ImproperlyConfigured("DATABASE_ROUTERS setting must contain 'django_pgschemas.routers.SyncRouter'.") 
開發者ID:lorinkoz,項目名稱:django-pgschemas,代碼行數:5,代碼來源:apps.py


注:本文中的django.conf.settings.DATABASE_ROUTERS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。