Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
def memberList(request,includeDevices):
    if request.method=='GET':
        members = Member.objects.all()
        if includeDevices == 'yes':
            serializer = MemberDeviceSerializer(members,many=True,context={'request': request})
        else:
            serializer  = MemberSerializer(members,many=True,context={'request': request})
        return JSONResponse(serializer.data)
    return JSONResponse("invalid_data",status = 400)