views.py 960 B

123456789101112131415161718192021222324252627282930
  1. from django.shortcuts import render
  2. # Create your views here.
  3. from rest_framework import status
  4. from rest_framework.response import Response
  5. from rest_framework.views import APIView
  6. from rest_framework.viewsets import ModelViewSet
  7. from workreport.models import DailyReport
  8. from workreport.serializers import DailyReportSerialiser
  9. class ReportView(APIView):
  10. def get(self, request):
  11. data = DailyReport.objects.values('title', 'content', 'content', 'create_at', 'id')
  12. return Response(data=data, status=status.HTTP_200_OK)
  13. def post(self, request):
  14. data = request.data
  15. report = DailyReport(title=data['title'], content=data['content'], create_by_id=data['create_by_id'])
  16. report.save()
  17. return Response(status=status.HTTP_201_CREATED)
  18. def delete(self, instance):
  19. pass
  20. class DailyReportView(ModelViewSet):
  21. queryset = DailyReport.objects.all()
  22. serializer_class = DailyReportSerialiser