【发布时间】:2017-08-09 04:15:27
【问题描述】:
我在 Employee 和 Manager 类之间有继承。员工 - 超类,经理 - 子类。
class Employee(models.Model):
###
name = models.CharField(max_length=50, null=False)
address = models.CharField(max_length=50, null=False)
###
class Manager(Employee):
department = models.CharField(max_length=50)
###
here I don't want the 'name' and 'address' fields of Employee class.
(I want other fields of Employee and department field of this class to be stored in
Manager table in database)
###
如何做到这一点。提前致谢。
【问题讨论】:
-
即使这是可能的,这将使
Manager没有名字。你确定要那个吗? -
在其他语言中,您将创建
Employeeprivate字段,而不是public或protected。 -
为什么不用foreingkey?
-
是的,我绝对希望将这些字段从 Manager 中完全删除
-
把你想要的字段放在一个abstract模型中,让Employee和Manager都继承?但实际上,我觉得这里根本不应该使用继承。
标签: python django inheritance