Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to forcefully delete in admin mode ? #88

Closed
mmohdnowfal opened this issue Sep 25, 2017 · 3 comments
Closed

Is there a way to forcefully delete in admin mode ? #88

mmohdnowfal opened this issue Sep 25, 2017 · 3 comments

Comments

@mmohdnowfal
Copy link

No description provided.

@Gagaro
Copy link
Member

Gagaro commented Sep 25, 2017

No, you have to do it in code. If it is a one use need, you can use manage.py shell.

@anuj9196
Copy link

anuj9196 commented Aug 7, 2019

I need this feature. In order to hard delete, I need to SSH to the server console and then execute the commands. A developer can do this but a manager with no knowledge of server handling can not do this.

@anuj9196
Copy link

anuj9196 commented Aug 7, 2019

A workaround for those who need.

Add a action to the admin using

class MyModelAdmin(SafeDeleteAdmin):
     ...
     
    actions = list(SafeDeleteAdmin.actions) + ['hard_delete_deleted_records']

    def hard_delete_deleted_records(self, request, queryset):
        data = queryset.all(
            force_visibility=DELETED_ONLY_VISIBLE
        )
        length = len(data)
        data.delete(force_policy=HARD_DELETE)
        self.message_user(request, '%s records deleted.' % length)

    hard_delete_deleted_records.short_description = 'Hard delete deleted records'

You can use By Deleted filter to get only deleted objects and select all objects in the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants