Home > database >  DeleteView - confirm by Popup windows
DeleteView - confirm by Popup windows

Time:12-10

I want to ask you, if you know, is here some point or solution how to do confirm delete item with DeleteView class by Popup bootstrap window. So I will not use template_name, but popup windows on current page.

Thank you so much for everything...!!!

To be more precise I have this button in my index.html page

 <button type="button"  data-toggle="modal" data-target="#exampleModal">
             In
        </button>

And here I have modal for deleting

            <div  id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div  role="document">
                <div >
                  <div >
                    <h5  id="exampleModalLabel">Are you sure to delete this?</h5>
                    <button type="button"  data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  </div>
                  <div >
                      <a href="#" >Yes</a>
                         <button type="button"  data-dismiss="modal">No</button>
                  </div>
                </div>
              </div>
            </div>
    </div>

and here is my views.py for delete

class ItemDeleteView(DeleteView):
 model = Item
 # template_name = 'index.html'
 success_url = reverse_lazy('index')
 login_url = '/accounts/login/'

 def get(self, request, *args, **kwargs):
    return self.post(request, *args, **kwargs)

and I don't know what to do. now... thanks

CodePudding user response:

Best option would be Javascript, but you could instead redefine the get method of your DeleteView class :

Add that to your class

def get(self, request, *args, **kwargs):
        return self.post(request, *args, **kwargs)

Basically the Deleteview need a post request to get trigger, it is a bit of a hack but works well.

In your template place this in your modal or popup

    <form method="POST" action="{% url "your_delete_url_name" %}">
   {% csrf_token %}<input type="submit" value="DELETE">
   </form>

Do not forget the object id in your URL

  • Related