Python 强制方法重写
我有一个抽象的django模型,其中包含一些必须由子类重写的方法。在实际调用方法之前(例如在迁移期间),是否有方法确保(通过抛出异常)方法已被重写 在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意Python 强制方法重写,python,django,Python,Django,我有一个抽象的django模型,其中包含一些必须由子类重写的方法。在实际调用方法之前(例如在迁移期间),是否有方法确保(通过抛出异常)方法已被重写 在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意 class MissingMethodException(BaseException): def __init__(self, message): super(MissingMethodExcepti
class MissingMethodException(BaseException):
def __init__(self, message):
super(MissingMethodException, self).__init__(message)
class BaseModel(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Meta:
abstract=True
def start(self):
#this will only throw an exception when called
raise MissingMethodException("Method start is missing")