所以,我找到了这个主题:Separate first, middle and last names (Python),并且我尝试使代码适应我在 OpenERP 上的需求。
我目前是这样的:
class get_the_name(object):
def __init__(self, fullname):
self.full = fullname
s = self.full.split()
try:
self.first = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
s = s[len(self.first.split()):]
self.middle = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
s = s[len(self.middle.split()):]
self.last = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
finally:
pass
class class_A(osv.osv):
_name = 'classA.classA'
_rec_name = 'name_of'
_columns = {
'name_of':fields.char('Name:', size = 10),
'description_':fields.char('Description:', size = 10),
'first_last':fields.function(get_the_name("Just testing this").first, method = True, string = "Split Name", type = "char", size = 50),
}
class_A()
虽然这给了我错误信息:
AttributeError:“str”对象没有属性“func_name”
就算这有话说,我也不想这样。而不是函数是:
'first_last':fields.function(get_the_name("Just testing this").first, method = True, string = "Split Name", type = "char", size = 50),
我希望它是:
'first_last':fields.function(get_the_name(name_of).first, method = True, string = "Split Name", type = "char", size = 50),
我怎样才能做到这一点?