1. class DataClass(object):
  2. @abstractmethod
  3. def aaa(self):
  4. raise NotImplemented
  5. @abstractmethod
  6. def bbb(self):
  7. raise NotImplemented
  8. class Patient(DataClass, models.Model):
  9. name = models.TextField(
  10. help_text='姓名',
  11. verbose_name=_('姓名'), max_length=20, default='', )
  12. telecom = models.CharField(
  13. help_text='手机号码',
  14. verbose_name=_('手机号码'),
  15. max_length=20, default='', )
  16. def __str__(self):
  17. return self.name or _('ID is %s') % self.id
  18. def aaa(self):
  19. return aaa(str(self.id))
  20. def bbb(self):
  21. return 'hello'

在类中必须重写了aaa和bbb函数,Patient类才可以被实例化,否则无法创建实例化对象

参考

https://blog.csdn.net/study_in/article/details/84841957