Esempio n. 1
0
    def post(self, request, format=None):
        ser = IdcSerializer(data=request.data)

        if ser.is_valid():
            ser.save()
            return Response(ser.data, status.HTTP_202_ACCEPTED)
        return Response(status=status.HTTP_400_BAD_REQUEST)
Esempio n. 2
0
    def put(self, request, pk, format=None):
        idc = self.get_object(pk)
        ser = IdcSerializer(idc, data=request.data)

        if ser.is_valid():
            ser.save()
            return Response(ser.data)
        return Response(status=status.HTTP_400_BAD_REQUEST)
Esempio n. 3
0
def idc_list(request, *args, **kwargs):
    if request.method == 'GET':
        # 列表
        queryset = Idc.objects.all()
        list_ser = IdcSerializer(queryset, many=True)
        return JSONResponse(list_ser.data)

    elif request.method == 'POST':
        content = JSONParser().parse(request)
        ser = IdcSerializer(data=content)

        if ser.is_valid():
            ser.save()
            return JSONResponse(ser.data)
Esempio n. 4
0
def idc_list_v2(request, *args, **kwargs):
    if request.method == 'GET':
        # 列表
        queryset = Idc.objects.all()
        list_ser = IdcSerializer(queryset, many=True)
        return Response(list_ser.data)

    elif request.method == 'POST':
        content = JSONParser().parse(request)
        ser = IdcSerializer(data=content)

        if ser.is_valid():
            ser.save()
            return Response(ser.data, status.HTTP_202_ACCEPTED)
        return Response(status=status.HTTP_400_BAD_REQUEST)
Esempio n. 5
0
def idc_detail(request, pk, *args, **kwargs):
    try:
        idc = Idc.objects.get(pk=pk)
    except Idc.DoesNotExist:
        return HttpResponse(status=404)
    if request.method == 'GET':
        # 详细
        ser = IdcSerializer(idc)
        return JSONResponse(ser.data)
    elif request.method == 'PUT':
        # 修改
        content = JSONParser().parse(request)
        ser = IdcSerializer(idc, data=content)

        if ser.is_valid():
            ser.save()
            return JSONResponse(ser.data)
    elif request.method == 'DELETE':
        # 删除
        idc.delete()
        return HttpResponse(status=204)
Esempio n. 6
0
def idc_detail_v2(request, pk, *args, **kwargs):
    try:
        idc = Idc.objects.get(pk=pk)
    except Idc.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        # 详细
        ser = IdcSerializer(idc)
        return Response(ser.data)
    elif request.method == 'PUT':
        # 修改
        content = JSONParser().parse(request)
        ser = IdcSerializer(idc, data=content)

        if ser.is_valid():
            ser.save()
            return Response(ser.data)
        return Response(status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'DELETE':
        # 删除
        idc.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Esempio n. 7
0
 def get(self, request, pk, format=None):
     idc = self.get_object(pk)
     ser = IdcSerializer(idc)
     return Response(ser.data)
Esempio n. 8
0
 def get(self, request, format=None):
     # 列表
     queryset = Idc.objects.all()
     list_ser = IdcSerializer(queryset, many=True)
     return Response(list_ser.data)