リストからエントリを削除する必要がある問題に取り組んでいます。アイテムが削除されたときにトースター メッセージを表示する必要があり、更新せずに削除された要素を削除したいですか? どうすればいいですか?ウェブ上で多くのリンクを試しましたが、どれもうまくいきませんでした。
ビュー.py
def centre_delete(request):
if request.is_ajax():
id = request.POST.get('id')
Centre.objects.get(pk=id).delete()
message = "Deleted Successfully"
else:
message = "Not Ajax"
return HttpResponse(message)
center_list.html
<script type="text/javascript">
$(document).ready(function() {
$(".del").click(function(){
swal(Delete centre?);
$.ajax({
type: "POST",
url: "/NewApp/centredelete/",
data: {
'id': $('#cendel').val()
},
success: function () {
#what should go here?
}
});
return false;
});
});
</script>
<body>
{% for c in centres %}
<tr>
<td>{{ c.name }}</td>
<td>{{ c.address }}</td>
<td>{{ c.contact }}</td>
<td>{{ c.phone }}</td>
<td>
<a href="{% url 'NewApp:centreupdate' slug=c.slug %} " style="color:black; margin-left:8px"><span class="glyphicon glyphicon-edit"></span></a>
<input type="hidden" id="cendel" value="{{ c.id }}">
<a class="btn btn-primary del" type="button" id="del">Delete</a></td>
</tr>
{% endfor %}
</body>