George B
George B

Reputation: 424

Django admin action delete_selected to be the last option in the drop-down list

I would like to display the delete_selected action in the drop-down list in the admin screen as the last option just for one model.

Upvotes: 1

Views: 163

Answers (1)

George B
George B

Reputation: 424

I managed to make it work like this. Would be there a nicer way?

class MyModelAdmin(admin.ModelAdmin):

    actions = ['soft_delete_selected', 'soft_undelete_selected']

    def get_actions(self, request):
        actions = super().get_actions(request)
    
        action = actions['delete_selected']
        del actions['delete_selected']
        actions['delete_selected'] = action

        return actions

Upvotes: 2

Related Questions