Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
ops
jumpserver
Commits
c4af6fa7
Commit
c4af6fa7
authored
Feb 18, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 创建子节点支持id
parent
49404f76
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
3 deletions
+4
-3
node.py
apps/assets/api/node.py
+2
-1
node.py
apps/assets/models/node.py
+2
-2
No files found.
apps/assets/api/node.py
View file @
c4af6fa7
...
...
@@ -163,12 +163,13 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
value
=
request
.
data
.
get
(
"value"
)
_id
=
request
.
data
.
get
(
'id'
)
or
None
values
=
[
child
.
value
for
child
in
instance
.
get_children
()]
if
value
in
values
:
raise
ValidationError
(
'The same level node name cannot be the same'
)
node
=
instance
.
create_child
(
value
=
value
)
node
=
instance
.
create_child
(
value
=
value
,
_id
=
_id
)
return
Response
(
self
.
serializer_class
(
instance
=
node
)
.
data
,
status
=
201
)
def
get_object
(
self
):
...
...
apps/assets/models/node.py
View file @
c4af6fa7
...
...
@@ -134,10 +134,10 @@ class Node(OrgModelMixin):
count
=
max
(
values
)
+
1
if
values
else
1
return
'{} {}'
.
format
(
name
,
count
)
def
create_child
(
self
,
value
):
def
create_child
(
self
,
value
,
_id
=
None
):
with
transaction
.
atomic
():
child_key
=
self
.
get_next_child_key
()
child
=
self
.
__class__
.
objects
.
create
(
key
=
child_key
,
value
=
value
)
child
=
self
.
__class__
.
objects
.
create
(
id
=
_id
,
key
=
child_key
,
value
=
value
)
return
child
def
get_children
(
self
,
with_self
=
False
):
...
...
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