1👍
✅
When if sveti.pk == request.GET['pk']:
is False, you don’t explicitly return anything and the view returns None
instead.
To delete a record, you’d need to use Model.delete()
method
if sveti.pk == request.GET['pk']:
sveti.delete()
return HttpResponse('{"success":true}')
return HttpResponse('{"success":false}')
would remedy both errors, or by returning a 404 response (not found).
However, I don’t see you actually querying for the right Sveti
object in your view, perhaps you meant to use the get_object_or_404()
function here:
def remove_sveti(request):
if not request.is_ajax():
raise Http404
sveti = get_object_or_404(Sveti, pk=request.GET['pk'])
sveti.delete()
return HttpResponse('{"success":true}')
The get_object_or_404()
function will raise a Http404
response if the object by that primary key doesn’t exist.
Source:stackexchange.com