修改判题数据库
This commit is contained in:
30
oj/db_router.py
Normal file
30
oj/db_router.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# coding=utf-8
|
||||
|
||||
|
||||
class DBRouter(object):
|
||||
def db_for_read(self, model, **hints):
|
||||
if model._meta.app_label == 'submission':
|
||||
return 'submission'
|
||||
return "default"
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if model._meta.app_label == 'submission':
|
||||
return 'submission'
|
||||
return "default"
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
return True
|
||||
|
||||
def allow_migrate(self, db, app_label, model=None, **hints):
|
||||
if app_label == "submission":
|
||||
if db == "submission":
|
||||
r = True
|
||||
else:
|
||||
r = False
|
||||
else:
|
||||
if db == "default":
|
||||
r = True
|
||||
else:
|
||||
r = False
|
||||
print db, app_label, r
|
||||
return r
|
||||
@@ -7,24 +7,26 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# 下面是需要自己修改的
|
||||
LOG_PATH = "LOG/"
|
||||
|
||||
# 注意这是web 服务器访问的地址,判题度武器访问的地址不一定一样,因为可能不在一台机器上
|
||||
# 注意这是web 服务器访问的地址,判题端访问的地址不一定一样,因为可能不在一台机器上
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
'CONN_MAX_AGE': 0.3,
|
||||
},
|
||||
'submission': {
|
||||
'NAME': 'oj_submission',
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'HOST': "121.42.32.129",
|
||||
'POST': 3306,
|
||||
'USER': 'root',
|
||||
'PASSWORD': 'mypwd'
|
||||
}
|
||||
}
|
||||
|
||||
# 这是web 服务器连接到mongodb 的地址
|
||||
MONGODB = {
|
||||
'HOST': '121.42.32.129',
|
||||
'USERNAME': 'root',
|
||||
'PASSWORD': 'root',
|
||||
'PORT': 27017
|
||||
}
|
||||
|
||||
DEBUG = True
|
||||
|
||||
# 同理 这是 web 服务器的上传路径
|
||||
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case')
|
||||
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
|
||||
|
||||
DATABASE_ROUTERS = ['oj.db_router.DBRouter']
|
||||
|
||||
Reference in New Issue
Block a user