Пример #1
0
def ipaddr_api(request):
        if request.method == 'GET':
                ipaddrs = ipaddr.objects.all()
                serializer = ipaddrSerializer(ipaddrs, many=True)
                return Response(serializer.data)
        elif request.method == 'POST':
                serializer = ipaddrSerializer(data=request.DATA)
                if serializer.is_valid():
                        serializer.save()
                        return Response(serializer.data, status=status.HTTP_201_CREATED)
                else:
                        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
def ipaddr_api_details(request,pk,format=None):
        if request.method == 'GET':
                ipaddrs = ipaddr.objects.filter(id=pk)
                serializer = ipaddrSerializer(ipaddrs, many=True)
                return Response(serializer.data)
        elif request.method == 'DELETE':
                ipaddrs = ipaddr.objects.filter(id=pk)
                ipaddrs.delete()
                return Response(status=status.HTTP_204_NO_CONTENT)
        elif request.method == 'POST':
                ipaddrs = ipaddr.objects.filter(id=pk)[0]
                serializer = ipaddrSerializer(ipaddrs, data=request.DATA, partial=True)
                if serializer.is_valid():
                        serializer.save()
                        return Response(serializer.data, status=status.HTTP_201_CREATED)
                else:
                        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)