Re: Django admin - action on delete

2011-01-07 Thread Subhranath Chunder
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.

On Fri, Jan 7, 2011 at 8:52 PM, galago  wrote:

> 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 :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Django admin - action on delete

2011-01-07 Thread galago
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 :)

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



Re: Django admin - action on delete

2011-01-07 Thread Mark (Nosrednakram)
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.

On Jan 7, 4:18 am, robos85  wrote:
> 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:/

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



Re: Django admin - action on delete

2011-01-07 Thread Scott Hebert (slaptijack)
On Jan 7, 5:18 am, robos85  wrote:
> 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:/

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

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



Django admin - action on delete

2011-01-07 Thread robos85
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:/

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