views.py 691 B

1234567891011121314151617181920
  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 workreport.models import DailyReport
  7. class DailyReportViews(APIView):
  8. def get(self, request):
  9. data = DailyReport.objects.values('title', 'content', 'create_at', 'create_by', 'id')
  10. return Response(data=data, status=status.HTTP_200_OK)
  11. def post(self, request):
  12. data = request.data
  13. report = DailyReport(title=data['title'], content=data['content'], create_by_id=data['create_by_id'])
  14. report.save()
  15. return Response(status=status.HTTP_201_CREATED)