Django admin - action on delete

3,641 views
Skip to first unread message

robos85

unread,
Jan 7, 2011, 6:18:33 AM1/7/11
to django...@googlegroups.com
What action is initialized when delete link is clicked?
I user save_model() to override default save action, but can't find action to override delete procedures. I need it:/

Scott Hebert (slaptijack)

unread,
Jan 7, 2011, 8:53:08 AM1/7/11
to Django users
Every model has a delete() method. You should be able to override it.

http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.delete

--
Scott Hebert
http://slaptijack.com

Mark (Nosrednakram)

unread,
Jan 7, 2011, 10:14:37 AM1/7/11
to Django users
There is a warning in on overriding delete, maybe not a concern for
you but worth knowing about.:

http://docs.djangoproject.com/en/dev/topics/db/models/

Note that the delete() method for an object is not necessarily called
when deleting objects in bulk using a QuerySet. To ensure customized
delete logic gets executed, you can use pre_delete and/or post_delete
signals.

galago

unread,
Jan 7, 2011, 10:22:10 AM1/7/11
to django...@googlegroups.com
I made what I wanted in
def log_deletion(self, request, object, object_repr):

It's not elegant, but in Django 1.3 there is a delete_model() function:)
But now I'm using 1.2.4 :)

Subhranath Chunder

unread,
Jan 7, 2011, 12:36:16 PM1/7/11
to django...@googlegroups.com
When deleting from the admin interface, the delete is actually on the entire QuerySet rather than on the object level. So if you need to perform some object level modification on the delete action of the admin interface, you can remove the default 'delete_selected' action, and go a custom delete action. Like:

class SomeModelAdmin(admin.ModelAdmin):
actions = ['custom_delete']
def custom_delete(self, request, queryset):
         for object in queryset:
perform_some_action(object)
object.delete()
custom_delete.short_description = "Delete selected items"

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

Thanks,
Subhranath Chunder.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages