Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin inline: select all for delete?

In django admin inline forms, there are checkboxes for deleting individual inline objects. Is there a way to enable selecting all of them at once for deletion?

like image 985
Lefunque Avatar asked Jul 02 '26 05:07

Lefunque


1 Answers

Here's a solution I worked out:

In templates/admin/edit_inline/tabular.html

{% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" class="selectall_checkbox"/></th>{% endif %}

and

<script type="text/javascript">
$('.selectall_checkbox').click(function(e) {
    $(e.target).closest('table').find(':checkbox').filter(function () { return /DELETE/.test(this.name); }).each(function () {    
      this.checked = e.target.checked;
    });
});
</script>
like image 113
Lefunque Avatar answered Jul 05 '26 00:07

Lefunque