Модал подтверждения для удаления объекта не появляется при нажатии на кнопку удаления в django
Я использую следующую библиотеку: https://pypi.org/project/django-bootstrap-modal-forms/, но моя проблема в том, что когда я нажимаю на иконку "удалить" в таблице, ничего не происходит. Я привел фрагменты кода ниже.
urls.py:
urlpatterns = [
#path('', include(router.urls)),
path('', views.index, name='index'),
#path('hosts', views.hosts, name='hosts'),
path('hosts', HostsView.as_view(), name='hosts'),
path('host/new', HostDefinitionView.as_view(), name='new_hostdef'),
path('hosts/delete/<int:pk>/', HostDeleteView.as_view(), name='delete_hostdef')]
views.py:
@method_decorator(login_required(login_url='/admin/login'), name='dispatch')
class HostsView(View):
model = AvailableHosts
template_name = 'generate_keys/hosts.html'
def get(self, request, *args, **kwargs):
hostdef_objs = AvailableHosts.objects.filter(host_developer_email = request.user.email)
host_definition_table = HostDefinitionTable(hostdef_objs)
return render(request, self.template_name, {'host_definition_table': host_definition_table})
class HostDeleteView(BSModalDeleteView):
model = AvailableHosts
success_url = "/hosts" # this shouldn't be hard coded i don't think
template_name = 'generate_keys/hosts_confirm_delete.html'
success_message = 'success'
tables.py:
class HostDefinitionTable(tables.Table):
host_label = tables.Column(verbose_name="Host")
host_activation_request = tables.Column()
hostdef_status = tables.Column('Operations')
class Meta:
model = AvailableHosts
fields = ("host_label",
"host_activation_request",
"hostdef_status")
template_name = "django_tables2/bootstrap4.html"
def render_hostdef_status(self, value, record):
tooltip = 'Delete host definition'
icon = 'fa fa-eraser'
return format_html(
'<button type="button" name="delete_hostdef" id="id_delete_hostdef" ' +
'class="btn btn-link btn-delete-hostdef" title="{}"' +
#'data-form-url="{% url "delete_hostdef" {} %}" ' +
'data-form-url="{}" ' +
'>' +
'<i class="{}"></i></button>', tooltip, reverse("delete_hostdef", args=(record.pk,)), icon
)
в hosts.html:
<script>
$(document).ready(function(){
console.log("document is ready")
$("#id_create_hostdef_button").modalForm({
formURL: "{% url 'new_hostdef' %}",
modalID: "#add-hostdef-modal"
});
function deleteHostModalForm() {
$(".btn-delete-hostdef").each(function() {
$(this).modalForm({
formURL: $(this).data('form-url'),
isDeleteForm: true
})
}) }
deleteHostModalForm()
в hosts_confirm_delete.html:
<form class="form ml-4 mr-4 mt-4" method="post", action="">
{% csrf_token %}
<div class="modal-header">
Confirm Delete
</div>
<div class="modal-body">
Are you sure you want to delete this host definition
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
<button type="submit" class="btn"
id="id_confirm_delete_hostdef" name="delete_hostdef" value="">
OK
</button>
</div>
</form>
Есть ли что-то, что я упускаю?