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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
DBRouter.py
physical/DBRouter.py
+17
-13
No files found.
physical/DBRouter.py
View file @
3f56b842
# !/usr/bin/env python
# -*- coding: utf-8 -*-
DATABASE_APPS_MAPPING
=
{
'face'
:
'face'
,
'commodity'
:
'commodity'
}
class
DBRouter
:
...
...
@@ -15,8 +16,8 @@ class DBRouter:
# if model._meta.app_label == 'face':
# return 'face'
if
model
.
_meta
.
app_label
==
'commodity'
:
return
'commodity'
if
model
.
_meta
.
app_label
in
DATABASE_APPS_MAPPING
:
return
DATABASE_APPS_MAPPING
[
model
.
_meta
.
app_label
]
return
None
def
db_for_write
(
self
,
model
,
**
hints
):
...
...
@@ -26,20 +27,22 @@ class DBRouter:
# if model._meta.app_label == 'face':
# return 'face'
if
model
.
_meta
.
app_label
==
'commodity'
:
return
'commodity'
if
model
.
_meta
.
app_label
in
DATABASE_APPS_MAPPING
:
return
DATABASE_APPS_MAPPING
[
model
.
_meta
.
app_label
]
return
None
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
"""
Allow relations if a model in the user app is involved.
# """
# if obj1._meta.app_label == 'face' or \
# obj2._meta.app_label == 'face':
# return True
if
obj1
.
_meta
.
app_label
==
'commodity'
or
\
obj2
.
_meta
.
app_label
==
'commodity'
:
db_obj1
=
DATABASE_APPS_MAPPING
.
get
(
obj1
.
_meta
.
app_label
)
db_obj2
=
DATABASE_APPS_MAPPING
.
get
(
obj2
.
_meta
.
app_label
)
if
db_obj1
and
db_obj2
:
if
db_obj1
==
db_obj2
:
return
True
else
:
return
False
else
:
return
None
def
allow_migrate
(
self
,
db
,
app_label
,
model_name
=
None
,
**
hints
):
...
...
@@ -47,8 +50,9 @@ class DBRouter:
Make sure the auth app only appears in the 'users_db'
database.
"""
# if app_label == 'face':
# return db == 'face'
if
app_label
==
'commodity'
:
return
db
==
'commodity'
if
db
in
DATABASE_APPS_MAPPING
.
values
():
return
DATABASE_APPS_MAPPING
.
get
(
app_label
)
==
db
elif
app_label
in
DATABASE_APPS_MAPPING
:
return
False
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