我有一个基类Person
和派生类Manager
以及Employee
. 现在,我想知道的是创建的对象是Manager
或Employee
.
该人如下:
from Project.CMFCore.utils import getToolByName
schema = getattr(Person, 'schema', Schema(())).copy() + Schema((TextField('FirstName', required = True, widget = StringWidget(label='First Name', i18n_domain='project')), TextField('Last Name', required = True, widget = StringWidget(label='Last Name', i18n_domain='i5', label_msgid='label_pub_city'))
class Manager(BaseContent):
def get_name(self):
catalog = getToolByName(self, "portal_catalog")
people = catalog(portal_type='Person')
person={}
for object in people:
fname = object.firstName
lname = object.lastName
person['name'] = fname+' '+ lname
# if the derived class is Employee then i would like go to the method title of employee and if its a Manager then go to the title method of Manager
person['post'] = Employee/Manager.title()
return person
对于经理和员工来说,他们就像(员工也相似,但有些不同的方法)
from Project.Person import Person
class Manager(Person):
def title(self):
return "Manager"
对于员工,标题是“员工”。当我创建Person
它时,它要么Manager
是Employee
. 当我得到 person 对象时,类是 Person,但我想知道它是来自派生类“Manager”还是“Employee”。