def addMember(request): if request.method =='POST': data = JSONParser().parse(request) serializer = MemberSerializer(data=data,context={'request': request}) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data,status = 201) return JSONResponse("invalid_data",status = 400)
def updateMember(request,pk): try: member = Member.objects.get(pk=pk) except Member.DoesNotExist: return HttpResponse(status=404) if request.method =='PUT': data = JSONParser().parse(request) serializer = MemberSerializer(member,data=data,context={'request': request}) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data,status = 201) return JSONResponse("invalid_data",status = 400) return JSONResponse("invalid_data",status = 400)