File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
1
from django .apps import AppConfig
2
+ from django .conf import settings
2
3
3
4
4
5
class CasbinAdapterConfig (AppConfig ):
@@ -7,4 +8,5 @@ class CasbinAdapterConfig(AppConfig):
7
8
def ready (self ):
8
9
from .enforcer import initialize_enforcer
9
10
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 1
1
import logging
2
2
from django .conf import settings
3
- from django .db import connection
3
+ from django .db import connection , connections
4
4
from django .db .utils import OperationalError , ProgrammingError
5
5
6
6
from casbin import Enforcer
@@ -64,7 +64,7 @@ def initialize_enforcer(db_alias=None):
64
64
try :
65
65
row = None
66
66
if db_alias :
67
- with connection [db_alias ].cursor () as cursor :
67
+ with connections [db_alias ].cursor () as cursor :
68
68
cursor .execute (
69
69
"""
70
70
SELECT app, name applied FROM django_migrations
You can’t perform that action at this time.
0 commit comments