I do it this way:

<input type="checkbox" name="todelete" value="{{ item.id }}"/>

and in the view:

todel = request.POST.getlist('todelete')
ItemWatchList.objects.filter(user=request.user,id__in=todel).delete()


On 04.01.2012 11:33, Martin Tiršel wrote:
Hello,

I have a list of items (from a model) I want to display with checkboxes (for deleting multiple objects at once). The same behaviour like in django admin (change list). I can do such thing in templates:

{% for item in item_list %}
<li>
<input type="checkbox" name="somename" value="item_{{ item.id }}">
{{ item }}
</li>
{% endfor %}

and in a view loop through somename list I get from POST and delete items. Is there a better Django way I should do it or this approach I wrote is correct? Is there a way I could use Django forms for processing the POST data and delete items in a form's method (so I can use it from multiple views)?

Thanks,
Martin


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to