Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
physical
Commits
3f56b842
Commit
3f56b842
authored
Jul 15, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
6f22f345
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
+19
-15
DBRouter.py
physical/DBRouter.py
+19
-15
No files found.
physical/DBRouter.py
View file @
3f56b842
# !/usr/bin/env python
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
DATABASE_APPS_MAPPING
=
{
'face'
:
'face'
,
'commodity'
:
'commodity'
}
class
DBRouter
:
class
DBRouter
:
...
@@ -15,8 +16,8 @@ class DBRouter:
...
@@ -15,8 +16,8 @@ class DBRouter:
# if model._meta.app_label == 'face':
# if model._meta.app_label == 'face':
# return 'face'
# return 'face'
if
model
.
_meta
.
app_label
==
'commodity'
:
if
model
.
_meta
.
app_label
in
DATABASE_APPS_MAPPING
:
return
'commodity'
return
DATABASE_APPS_MAPPING
[
model
.
_meta
.
app_label
]
return
None
return
None
def
db_for_write
(
self
,
model
,
**
hints
):
def
db_for_write
(
self
,
model
,
**
hints
):
...
@@ -26,29 +27,32 @@ class DBRouter:
...
@@ -26,29 +27,32 @@ class DBRouter:
# if model._meta.app_label == 'face':
# if model._meta.app_label == 'face':
# return 'face'
# return 'face'
if
model
.
_meta
.
app_label
==
'commodity'
:
if
model
.
_meta
.
app_label
in
DATABASE_APPS_MAPPING
:
return
'commodity'
return
DATABASE_APPS_MAPPING
[
model
.
_meta
.
app_label
]
return
None
return
None
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
"""
"""
Allow relations if a model in the user app is involved.
Allow relations if a model in the user app is involved.
# """
# """
# if obj1._meta.app_label == 'face' or \
db_obj1
=
DATABASE_APPS_MAPPING
.
get
(
obj1
.
_meta
.
app_label
)
# obj2._meta.app_label == 'face':
db_obj2
=
DATABASE_APPS_MAPPING
.
get
(
obj2
.
_meta
.
app_label
)
# return True
if
db_obj1
and
db_obj2
:
if
obj1
.
_meta
.
app_label
==
'commodity'
or
\
if
db_obj1
==
db_obj2
:
obj2
.
_meta
.
app_label
==
'commodity'
:
return
True
return
True
else
:
return
None
return
False
else
:
return
None
def
allow_migrate
(
self
,
db
,
app_label
,
model_name
=
None
,
**
hints
):
def
allow_migrate
(
self
,
db
,
app_label
,
model_name
=
None
,
**
hints
):
"""
"""
Make sure the auth app only appears in the 'users_db'
Make sure the auth app only appears in the 'users_db'
database.
database.
"""
"""
# if app_label == 'face':
if
db
in
DATABASE_APPS_MAPPING
.
values
():
# return db == 'face'
return
DATABASE_APPS_MAPPING
.
get
(
app_label
)
==
db
if
app_label
==
'commodity'
:
elif
app_label
in
DATABASE_APPS_MAPPING
:
return
db
==
'commodity'
return
False
return
None
return
None
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment