fix(Node): Node 保存的时候,在信号里设置 parent_key

pull/5106/head
xinwen 4 years ago committed by Jiangjie.Bai
parent 91081d9423
commit a4667f3312

@ -201,10 +201,8 @@ class NodeAddChildrenApi(generics.UpdateAPIView):
def put(self, request, *args, **kwargs): def put(self, request, *args, **kwargs):
instance = self.get_object() instance = self.get_object()
nodes_id = request.data.get("nodes") nodes_id = request.data.get("nodes")
children = [get_object_or_none(Node, id=pk) for pk in nodes_id] children = Node.objects.filter(id__in=nodes_id)
for node in children: for node in children:
if not node:
continue
node.parent = instance node.parent = instance
return Response("OK") return Response("OK")

@ -103,7 +103,7 @@ class FamilyMixin:
if value is None: if value is None:
value = child_key value = child_key
child = self.__class__.objects.create( child = self.__class__.objects.create(
id=_id, key=child_key, value=value, parent_key=self.key, id=_id, key=child_key, value=value
) )
return child return child

@ -4,7 +4,7 @@ from operator import add, sub
from assets.utils import is_asset_exists_in_node from assets.utils import is_asset_exists_in_node
from django.db.models.signals import ( from django.db.models.signals import (
post_save, m2m_changed, pre_delete, post_delete post_save, m2m_changed, pre_delete, post_delete, pre_save
) )
from django.db.models import Q, F from django.db.models import Q, F
from django.dispatch import receiver from django.dispatch import receiver
@ -37,6 +37,11 @@ def test_asset_conn_on_created(asset):
test_asset_connectivity_util.delay([asset]) test_asset_connectivity_util.delay([asset])
@receiver(pre_save, sender=Node)
def on_node_pre_save(sender, instance: Node, **kwargs):
instance.parent_key = instance.compute_parent_key()
@receiver(post_save, sender=Asset) @receiver(post_save, sender=Asset)
@on_transaction_commit @on_transaction_commit
def on_asset_created_or_update(sender, instance=None, created=False, **kwargs): def on_asset_created_or_update(sender, instance=None, created=False, **kwargs):

Loading…
Cancel
Save