#API View
@api_view(['GET'])
def clientDetail(request,pk):
details = ClientAPI.objects.get(id=pk)
serializer = ClientSerializer(details,many=False)
return Response(serializer.data)
#API List
@api_view(['GET'])
def clientDetailList(request):
list = ClientAPI.objects.all().order_by('-id')
serializer = ClientSerializer(list,many=True)
return Response(serializer.data)
Here is my api view code .Now how i add delete function to delete the client detail list.
I try to delete my client details list .Can you show me the function i add my views.py
CodePudding user response:
It just like detail:
from rest_framework import status
#API View
@api_view(['DELETE'])
def clientDelete(request,pk):
client = ClientAPI.objects.get(id=pk)
client.delete() # or something your code.
return Response({
"message": "Client was deleted."
},status=status.HTTP_204_NO_CONTENT)
CodePudding user response:
I want to delete this list item. I try your code but I couldn't delete this list HTTP 200 OK Allow: GET, OPTIONS Content-Type: application/json Vary: Accept
[ { "id": 9, "status": "True", "inputvalues": "[10, 9, 7, 6, 5, 4, 3, 2, 1]", "timestamp": "2022-11-09T05:22:52.357502Z" }, { "id": 8, "status": "True", "inputvalues": "[99, 77, 69, 44, 10, 6, 5, 2, 1]", "timestamp": "2022-11-08T11:45:53.320006Z" }, { "id": 7, "status": "False", "inputvalues": "[19, 14, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", "timestamp": "2022-11-08T11:24:36.862230Z" }, { "id": 6, "status": "True", "inputvalues": "[11, 10, 9, 7, 6, 5, 1]", "timestamp": "2022-11-08T11:21:14.914640Z" }, { "id": 5, "status": "False", "inputvalues": "[133131]", "timestamp": "2021-09-24T17:11:08.217355Z" }, { "id": 4, "status": "False", "inputvalues": "[133131]", "timestamp": "2021-09-24T17:10:20.041078Z" }, { "id": 3, "status": "False", "inputvalues": "[8, 7, 6, 5, 4, 3, 1]", "timestamp": "2021-09-24T16:09:09.074813Z" }, { "id": 2, "status": "True", "inputvalues": "[4, 3, 2, 1]", "timestamp": "2021-09-24T16:08:09.207566Z" }, { "id": 1, "status": "False", "inputvalues": "[8, 6, 6, 5, 5, 4, 4]", "timestamp": "2021-09-24T15:51:32.396178Z" } ]
CodePudding user response:
[After entering your code result is like the first picture but I couldn't delete the client details list information]