diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 4ea1c09b97..d35284135c 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -101,3 +101,40 @@ class AjaxUpdateView(AjaxView, UpdateView): else: return response + + +class AjaxDeleteView(AjaxView, DeleteView): + + def post(self, request, *args, **kwargs): + + if request.is_ajax(): + obj = self.get_object() + pk = obj.id + obj.delete() + + data = {'id': pk, + 'delete': True} + + return JsonResponse(data) + + else: + return super(DeleteView, self).post(request, *args, **kwargs) + + def get(self, request, *args, **kwargs): + + response = super(DeleteView, self).get(request, *args, **kwargs) + + if request.is_ajax(): + + data = {'id': self.get_object().id, + 'title': self.ajax_form_title, + 'delete': False, + 'html_data': render_to_string(self.getAjaxTemplate(), + self.get_context_data(), + request=request) + } + + return JsonResponse(data) + + else: + return response diff --git a/InvenTree/part/templates/part/delete.html b/InvenTree/part/templates/part/delete.html index 5e536508d9..9e38b07be4 100644 --- a/InvenTree/part/templates/part/delete.html +++ b/InvenTree/part/templates/part/delete.html @@ -7,37 +7,6 @@ {% block del_body %} - {% if part.used_in_count %} -

This part is used in BOMs for {{ part.used_in_count }} other parts. If you delete this part, the BOMs for the following parts will be updated: -