瀏覽代碼

树练习的put接口实现

DYaiu 4 年之前
父節點
當前提交
3bca961948
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. 10 1
      workTtree/views.py

+ 10 - 1
workTtree/views.py

@@ -1,4 +1,4 @@
-from django.db.models import F, ExpressionWrapper, BooleanField
+from django.db.models import F
 from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
@@ -34,6 +34,15 @@ class SchoolDeptViews(APIView):
         data.pop('_state')
         return Response(data=data, status=status.HTTP_200_OK)
 
+    def put(self, request):
+        data = request.data
+        parent = SchoolDept.objects.get(id=data['id'])
+        parent.name = data['name']
+        parent.save()
+        d = parent.__dict__
+        d.pop('_state')
+        return Response(data=d, status=status.HTTP_200_OK)
+
     def delete(self, request):
         try:
             # 当传递的id值不存在数据库或没有传id值直接捕获异常