2013-05-14 64 views

回答

2

這裏有一個解決方案,我摸索出:

在模板/管理/ 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 %} 

<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> 
0

這裏是一個類似的解決方案,但插入複選框用jQuery在admin/base_site.html模板的頁腳塊中:

{% extends "admin/base.html" %} 
... 

{% block footer %} 
<script type="text/javascript"> 
var $ = django.jQuery; 
$(document).ready(function() { 
    $('.tabular table th:contains({% trans "Delete?" %})').each(function(index) { 
     var text = $(this).text(); 
     $(this).html('<input type="checkbox" class="selectall_checkbox">&nbsp; ' + text); 
    }); 
    $('.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> 
{% endblock footer %}