views.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from random import random
  2. from django.shortcuts import render
  3. # Create your views here.
  4. from rest_framework import status
  5. from rest_framework.response import Response
  6. from rest_framework.views import APIView
  7. from rest_framework.viewsets import ModelViewSet
  8. from detailmptt.models import DailyMptt
  9. from workreport.models import DailyRreport
  10. from workreport.serializer import DailyReportSerializer
  11. class DetailMpttView(APIView):
  12. # def get(self,request):
  13. # objects_all = DailyMptt.objects.all()
  14. # dailyMpttList =
  15. #设置查询条件
  16. def get(self,request):
  17. dailyMptt = DailyMptt()
  18. #获取全部get信息
  19. params = request.GET
  20. #赋值
  21. dailyMptt.getObject(params)
  22. parent_id = params.get('parent_id')
  23. dailyMpttList = DailyMptt.objects.filter(parent_id = parent_id).values()
  24. return Response(data=dailyMpttList, status=status.HTTP_200_OK)
  25. def post(self, request):
  26. # pass
  27. data = request.data
  28. dailyMptt = DailyMptt()
  29. dailyMptt.getObject(data)
  30. dailyMptt.save()
  31. return Response(status = status.HTTP_201_CREATED)
  32. def delete(self, request):
  33. id = request.data['id']
  34. DailyMptt.objects.filter(id = id).delete()
  35. return Response(data=True, status=status.HTTP_200_OK)