开发者

Django - Overriding model's delete() method in base class - recursive problem

开发者 https://www.devze.com 2023-01-24 19:53 出处:网络
I have a abstract class which has some common methods for all of my models. I have inherited this class in all my models. Now there is a requirement to send the mail whenever a model is deleted. So I

I have a abstract class which has some common methods for all of my models. I have inherited this class in all my models. Now there is a requirement to send the mail whenever a model is deleted. So I have override the delete() method in my abstract class. This leads to the recursive call of same method because calling the super method.

    super(Model, self).save(*args,开发者_如何学Go **kwargs) 

    class Common(models.Model): 
             #mail logic
             super(type(self), self).delete(*args, **kwargs)        

    class Child(Common)      
             # fields


This is why you must always use the proper type instead of type(self).

super(Common, self).delete(*args, **kwargs)
0

精彩评论

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