Browse Source

树练习的post接口实现

DYaiu 4 years ago
parent
commit
675d1e144d
1 changed files with 10 additions and 0 deletions
  1. 10 0
      workTtree/views.py

+ 10 - 0
workTtree/views.py

@@ -23,3 +23,13 @@ class SchoolDeptViews(APIView):
         for res in resData:
             res['childer'] = res['childer'] // 2 != 0
         return Response(data=resData, status=status.HTTP_200_OK)
+
+    def post(self, request):
+        reqData = request.data
+        # 获取前端给的父类id获取父类
+        parent = SchoolDept.objects.get(id=reqData['id'])
+        # 对象类型转换成dict类型
+        data = SchoolDept.objects.create(name=reqData['name'], parent=parent).__dict__
+        # 不删除该属性会转换json错误
+        data.pop('_state')
+        return Response(data=data, status=status.HTTP_200_OK)