开发者

Modify Django user delete method?

开发者 https://www.devze.com 2023-01-11 21:21 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号