views.py 917 B

123456789101112131415161718192021222324252627
  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.serializer import DailyReportSerializer
  9. class DailyReportViews(APIView):
  10. def get(self, request):
  11. data = DailyReport.objects.values('title', 'content', 'create_at', 'create_by', '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. class ReportViews(ModelViewSet):
  19. queryset = DailyReport.objects.all()
  20. serializer_class = DailyReportSerializer