django admin 修改批量操作内容
@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
本文来自博客园,作者:Python界-黄药师,转载请注明原文链接:https://www.cnblogs.com/niehaidong111/p/9166031.html