Modify Django user delete method?
If I go to the Django ad开发者_JAVA技巧min page and delete a user, I want it to run some code before/after it deletes the user. I know about overriding models' delete()
methods, but I'm not sure how to apply it to a built-in model. Also, I'd like to be able to do it without 'subclassing' the User
model and creating a (for instance) MyUser
model.
Is there any way to accomplish this?
yes, you can listen to the django pre_delete and post_delete signal: here is the doc link: http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_delete http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_delete
精彩评论