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 = '删除所选'
View Code
 def has_delete_permission(self, request, obj=None):
        if obj and obj.questionnaire.exists():
            return False
是否显示删除按钮

 

posted @ 2018-06-11 10:47  Python界-黄药师  阅读(1919)  评论(0编辑  收藏  举报