@admin.register(models.PrizeJoinLog)
class PrizeJoinLogAdmin(admin.ModelAdmin):
actions = ['draw_prize']
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(PrizeJoinLogAdmin, self).changelist_view(request, extra_context)
def draw_prize(self, request, queryset):
pass
draw_prize.short_description = '开始抽奖'
draw_prize.type = 'warning'
draw_prize.confirm = '确认即开始抽奖并发送中奖通知~'
draw_prize.acts_on_all = True # 重要