I'm using Django. I created a function for delete button. it's working fine but the problem is : There is a template which is shared in two places (one is for url: /employer/job/edit and other is for vendor/job/edit) template is same for both. my code is as following which is working fine with /employer/job/edit but not working for vendor/job/edit.
Button code is :
<a style="cursor:pointer;" class="delete"
data-pk="{{ i.id }}" data-appname="employer" data-modelname="office">
<i class="fa fa-times font-18 iconcolor pt3 float-r" ></i>
</a>
JQUERY IS :
$('.delete').click(function() {
appname = $(this).data('appname');
modelname = $(this).data('modelname');
pk = $(this).data('pk');
delete_this = $(this);
$.ajax({
url: "/delete_button/" + appname + "/" + modelname + "/" + pk + "/",
type: "DELETE",
success: function() {
// Remove the HTML Element which represents you data
delete_this.parent().parent().parent().parent().remove();
$('#'+pk).remove();
location.reload(true);
}
});
});
and my function which i wrote in view.py is:
def delete_data(request, app_name, model_name, pk):
try:
model_name = get_model(app_name, model_name)
if request.method=='DELETE':
model_name.objects.get(id=pk).delete()
return HttpResponse('deleted', status=200)
except Exception, e:
return HttpResponse('error', status=500)
what is wrong, i'm doing. please help me out!!