Пример #1
0
def ipaddr_dns_name_api(request):
    if request.method == 'GET':
        ipaddr_dns_names = ipaddr_dns_name.objects.all()
        serializer = ipaddr_dns_nameSerializer(ipaddr_dns_names, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = ipaddr_dns_nameSerializer(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_dns_name_api_details(request,pk,format=None):
    try:
	ipaddr_dns_names = ipaddr_dns_name.objects.filter(id=pk)
    except ipaddr_dns_name.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        serializer = ipaddr_dns_nameSerializer(ipaddr_dns_names, many=True)
        return Response(serializer.data)
    elif request.method == 'DELETE':
                ipaddr_dns_name.delete()
                return Response(status=status.HTTP_204_NO_CONTENT)