コード例 #1
0
ファイル: views.py プロジェクト: pratush07/DocFinder
def doctor_list(request):
    """
    List all tasks, or create a new task.
    """
    if request.method == 'GET':
        doctors = Doctor.objects.all()
        serializer = DoctorSerializer(doctors, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = DoctorSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            getid=Doctor.objects.filter(email=request.data["email"])
            print getid[0].id
            dict1 = {'doc_id':getid[0].id, 'rate':'0', }   
            qdict = QueryDict('',mutable=True)
            qdict.update(dict1)
            serializer2=AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()

            dict2 = {'doc_id':getid[0].id, 'rate': '0',}
            qdict = QueryDict('',mutable=True)
            qdict.update(dict2)
            serializer2=AverageComRateSerializer(data=dict2)
            if serializer2.is_valid():
                serializer2.save()
                
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
def doctor_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        doctor = Doctor.objects.get(pk=pk)
    except Doctor.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = DoctorSerializer(doctor)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = DoctorSerializer(doctor, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        doctor.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
コード例 #3
0
ファイル: views.py プロジェクト: pratush07/DocFinder
def doctor_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        doctor = Doctor.objects.get(pk=pk)
    except Doctor.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = DoctorSerializer(doctor)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = DoctorSerializer(doctor, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        doctor.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
コード例 #4
0
def doctor_list(request):
    """
    List all tasks, or create a new task.
    """
    if request.method == 'GET':
        doctors = Doctor.objects.all()
        serializer = DoctorSerializer(doctors, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = DoctorSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            getid = Doctor.objects.filter(email=request.data["email"])
            dict1 = {
                'doc_id': getid[0].id,
                'rate': '0',
            }
            qdict = QueryDict('', mutable=True)
            qdict.update(dict1)
            serializer2 = AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()

            dict2 = {
                'doc_id': getid[0].id,
                'rate': '0',
            }
            qdict = QueryDict('', mutable=True)
            qdict.update(dict2)
            serializer2 = AverageComRateSerializer(data=dict2)
            if serializer2.is_valid():
                serializer2.save()

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)