I have a ListView and a DeleteView
class MyDeleteView(DeleteView):
success_url = reverse('list')
I want the option to delete the items in the ListView. I know how to do it if I accept the confirmation page in the DeleteView, but I don't want no template in my DeleteView. I just want to delete the item and send the user back.
I guess it should be with POST parameters, but what should the HTML look like? I guess it's something like:
<form method="post" action="/delete/">
<ul>
<li>Item1 (<input type="submit" value="Delete" />)</li>
<li>Item2 (<input type="submit" value="Delete" />)</li>
<li>Item3 (<input type="submit" value="Delete" />)</li>
</ul>
</form>
Can anyone lead me in the right direction? Thank you.
You're already heading the right way, with POST.
<ul>{% for item in object_list %}
<li><form method="post" action="{% url 'mydelete' pk=item.pk %}">
{{item}} (<input type="submit" value="Delete" />)
</form></li>
{% endif %}</ul>
I'm not entirely sure if the the inputs can go directly in a form in the HTML spec you're trying to adhere to. So you might have to sprinkle this idea with some spans or containers.
If the input submit, doesn't give your designers enough styling freedom, you could use them as the <noscript>
fallback and add some <button>
or javascript: link for the pretty version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With