【Django Admin】自动按钮BUG修复,请选中至少一个选项!
# templates/admin/actions.html
# 搜索找到: 需要做国际化 替换一下代码块
//TODO 需要做国际化
if (data_name.substr(0, 3) == "fc_"){
// 强制运行, 不用选择数据. 按钮名data_name必须以"fc_"开头.
done.call(this);
} else if (checkbox_checked == 0 && data_name != "add_item" && !_action.customButton[data_name].action_url) {
_vue.$alert(getLanuage("Please select at least one option!"), '', {
type: 'warning'
})
} else if (confirm) {
_vue.$confirm(confirm, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => done.call(this));
} else {
done.call(this)
}
# admin.py
# 重写 changelist_view
def changelist_view(self, request, extra_context=None):
if 'action' in request.POST and request.POST['action'].startswith('fc_'):
if not request.POST.getlist(ACTION_CHECKBOX_NAME):
post = request.POST.copy()
for u in models.数据表.objects.all():
post.update({ACTION_CHECKBOX_NAME: str(u.id)})
request.POST = post
return super(AdminName, self).changelist_view(request, extra_context)
# admin.py
# 这里要注意自定义的按钮命名 前面必须要有fc_前缀
actions = ['fc_request_data']
def fc_request_data(self,request,queryset):
print("自定义放方法")
Python全栈(后端、数据分析、脚本、爬虫、EXE客户端) / 前端(WEB,移动,H5) / Linux / SpringBoot / 机器学习