我有一个基类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”。