from django.http import JsonResponse from .models import Employee from .serializers import EmployeeSerializer from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status @api_view(['GET', 'POST']) def read_create_employees(request): if request.method == 'GET': employees = Employee.objects.all() serializer = EmployeeSerializer(employees, many=True) return JsonResponse(serializer.data, safe=False) if request.method == 'POST': serializer = EmployeeSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED)