(sorry for my bad english)
I need to delete an object, but directly from a list of the objects that y have in my template.
I have a work orders, that have spare
In your html template inside for loop use the form tag inside add urlpattern in urls.py delete view will be like below in views.py Note: import necessary imports shown in links or you need not to worry if you are using IDE such as pyCharm it will prompt you which import to make. to create delete button as below (css class will work if you are using bootstrap3):
url(r'^delete-entry/(?P
class DeleteView(SuccessMessageMixin, DeleteView):
model = OrderSparePart
success_url = '/'
success_message = "deleted..."
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
name = self.object.name
request.session['name'] = name # name will be change according to your need
message = request.session['name'] + ' deleted successfully'
messages.success(self.request, message)
return super(DeleteView, self).delete(request, *args, **kwargs)