我想实现Django中抽象继承与下面的代码,但它会产生一个最大递归深度误差。 我试图重写一个模型的save
方法。
class BaseModel(models.Model):
class Meta:
abstract = True
def save(self, *args, **kwargs):
#i'm doing something here
#i think the problem is in the return statement specifically because of the
#self.__class__ expression.
return super(self.__class__, self).save(*args, **kwargs)
class MyModel(BaseModel):
p = models.CharField(max_length=30)
产生这个错误(跟踪的结束,这是漫长的):
File "/home/jultra/ap3w/jultra_01/mysite/testsite/models.py", line 10, in save
return super(self.__class__, self).save(*args, **kwargs)
File "/home/jultra/ap3w/jultra_01/mysite/testsite/models.py", line 10, in save
return super(self.__class__, self).save(*args, **kwargs)
File "/home/jultra/ap3w/jultra_01/mysite/testsite/models.py", line 10, in save
return super(self.__class__, self).save(*args, **kwargs)
File "/home/jultra/ap3w/jultra_01/mysite/testsite/models.py", line 10, in save
return super(self.__class__, self).save(*args, **kwargs)
RuntimeError: maximum recursion depth exceeded