@admin.register(CbsProcessPathConf)
class CbsProcessPathConfAdmin(ImportMixin, ExportActionMixin, ModelAdmin):
# 添加导入模板按钮
actions = ['down_template']
def changelist_view(self, request, extra_context=None):
try:
action = self.get_actions(request)[request.POST['action']][0]
action_acts_on_all = action.acts_on_all
except (KeyError, AttributeError):
action_acts_on_all = False
if action_acts_on_all:
post = request.POST.copy()
post.setlist(admin.helpers.ACTION_CHECKBOX_NAME,
self.model.objects.values_list('id', flat=True))
request.POST = post
return super(CbsProcessPathConfAdmin, self).changelist_view(request, extra_context)
down_template.short_description = '下载导入模板'
down_template.type = 'danger'
#添加acts_on_all属性,设true值,changelist_view检查到action有个acts_on_all 属性,就会自动带上对象
down_template.acts_on_all = True
django admin action操作,没有选择对象时也能执行
于 2022-06-29 16:16:43 首次发布