django admin 修改批量操作内容

时间:2022-12-13 16:25:47
@admin.register(Template)
class TemplateAdmin(admin.ModelAdmin):
list_display = (
'cn_title', 'start_time', 'end_time', 'for_cma', 'for_pwa', 'for_mpa',
'for_cc', 'for_ata', 'avg_score', 'actor')
list_editable = ['for_cma', 'for_pwa', 'for_mpa', 'for_cc', 'for_ata']
actions = ['delete_selected', ] def delete_selected(self, request, queryset):
flag = True
for i in queryset:
if i.questionnaire.exists():
self.message_user(request, '已经有人答卷,无法删除!!')
flag = False
break
else:
continue
if flag:
queryset.delete()
self.message_user(request, '删除成功!!') delete_selected.short_description = '删除所选'
 def has_delete_permission(self, request, obj=None):
if obj and obj.questionnaire.exists():
return False

是否显示删除按钮