Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 强制方法重写_Python_Django - Fatal编程技术网

Python 强制方法重写

Python 强制方法重写,python,django,Python,Django,我有一个抽象的django模型,其中包含一些必须由子类重写的方法。在实际调用方法之前(例如在迁移期间),是否有方法确保(通过抛出异常)方法已被重写 在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意 class MissingMethodException(BaseException): def __init__(self, message): super(MissingMethodExcepti

我有一个抽象的django模型,其中包含一些必须由子类重写的方法。在实际调用方法之前(例如在迁移期间),是否有方法确保(通过抛出异常)方法已被重写

在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意在这种情况下提高更好。也可以使用,但是注意
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")