File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from django .apps import AppConfig
2+ from django .conf import settings
23
34
45class CasbinAdapterConfig (AppConfig ):
@@ -7,4 +8,5 @@ class CasbinAdapterConfig(AppConfig):
78 def ready (self ):
89 from .enforcer import initialize_enforcer
910
10- initialize_enforcer ()
11+ db_alias = getattr (settings , "CASBIN_DB_ALIAS" , "default" )
12+ initialize_enforcer (db_alias )
Original file line number Diff line number Diff line change 11import logging
22from django .conf import settings
3- from django .db import connection
3+ from django .db import connection , connections
44from django .db .utils import OperationalError , ProgrammingError
55
66from casbin import Enforcer
@@ -64,7 +64,7 @@ def initialize_enforcer(db_alias=None):
6464 try :
6565 row = None
6666 if db_alias :
67- with connection [db_alias ].cursor () as cursor :
67+ with connections [db_alias ].cursor () as cursor :
6868 cursor .execute (
6969 """
7070 SELECT app, name applied FROM django_migrations
You can’t perform that action at this time.
0 commit comments