Browse Source

树练习的put接口实现

DYaiu 4 years ago
parent
commit
3bca961948
1 changed files with 10 additions and 1 deletions
  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值直接捕获异常