@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 = '删除所选'