我在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)当我单击On按钮时,我想运行以下脚本,但我不知道如何运行。请帮帮我。
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>发布于 2019-03-13 06:51:26
要向管理添加媒体,只需将其添加到管理类的元类媒体中,例如:
class FooAdmin(admin.ModelAdmin):
# regular stuff
class Media:
js = (
'//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', # jquery
'app/js/myscript.js', # app static folder
)您可以添加自定义逻辑来选择HTML元素,并在JS中执行您想做的事情。
https://stackoverflow.com/questions/55135864
复制相似问题