我在Django管理列表中创建了以下功能!
admin.py
class LawyerAdmin(admin.ModelAdmin):
list_display = ('lawyer_idx', 'show_firm_url', 'lawyer_name', 'lawyer_birthday', 'lawyer_mobile', 'lawyer_license_num', 'like_cnt', 'recommend_name', 'register_date', 'status', 'lawyer_agent',)
list_filter = ['lawyer_status']
def status(self, obj):
if obj.lawyer_status == "W":
html = "Awaiting certification<br> <input type='button' value='certification' onclick='lawyer_confirm({0})'>"
return format_html(html, obj.lawyer_idx)
admin.site.register(Lawyer, LawyerAdmin)
当我单击“单击”按钮时,我想运行以下脚本,但不知道如何运行。请帮助我。
1. I want to implement the on-click function.
2. How to run a script
<script>
function lawyer_confirm(lawyer_idx) {
if (confirm('Certified?') == true) {
$.ajax({
url: '/admin/lawyer/view/lawyer_confirm',
data: {
lawyer_idx : lawyer_idx
},
dataType: "json",
type: 'post',
success: function(result){
alert(result.msg);
if (result.code == '0' ) {
location.href = result.retURL;
}
}
});
}
}
</script>