Django管理员更改列表隐藏复选框

时间:2018-11-12 14:26:54

标签: django

是否可以在管理更改列表中隐藏一些复选框,这是默认添加的复选框。我宁愿不扩展它。我在追求这样的事情

if obj.name == 'read only':
    #hide the checkbox of that row

添加了我要更改的框的示例

enter image description here

谢谢

赠予

1 个答案:

答案 0 :(得分:0)

这就是我最终要做的。在我的管理员中,我使用函数链接到js文件

class TemplateAdmin(admin.ModelAdmin):
    class Media:
        js = (
            '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', # jquery
            'js/admin-help.js',       # project static folder
        )

然后,在我的js文件中,我遍历表以在单元格中寻找一个名为“只读”的值。然后,我将“动作选择”复选框设置为“禁用”。

function read_only_checkboxes(){
     $("#result_list").find("tr").each(function() { //get all rows in table
        getType = $(this).find('td.field-api_type').text();
        if (getType == 'read only'){
            $(this).find('input.action-select').attr("disabled", true);
        }
    });
}

这有效,并且给了我想要的效果

谢谢

赠予

相关问题