Created
July 19, 2017 21:51
-
-
Save cantoniazzi/9d4428716208e0bd66d6b9fab4c58828 to your computer and use it in GitHub Desktop.
template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on("click", ".btn-remove", function() { | |
var id = $(this).attr("data-id"); | |
var uri = '/sua-rota-de-remocao-de-registros'; | |
$.ajax({ | |
type: "POST", | |
url: uri, | |
success: function (data) { | |
// aqui entra sua lógica de ocultar o elemento removido | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table> | |
{% for registro in registros %} | |
<tr> | |
<td> | |
{{ registro.id }} | |
</td> | |
<td> | |
{{ registro.nome }} | |
</td> | |
<td> | |
<button class="btn btn-remove" data-id="{{ registro.id }}">Delete</button> | |
</td> | |
</tr> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
def delete(request, id): | |
data = {'success': 0} | |
if request.method == 'POST': | |
try: | |
registro = Registro.objects.get(id=id) | |
except ObjectDoesNotExist: | |
registro = None | |
if registro: | |
registro.delete() | |
data['success'] = 1 | |
return JsonResponse(data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment