[quote author=Peter Seng link=topic=5748.msg14197#msg14197 date=1360812735]
假设我们创建了一个contract对象:
<br />class hr_contract(osv.osv):<br /> _name = 'hr.contract'<br /> _description = 'Contract'<br /> _columns = {<br /> 'name' : fields.char('Contract Name', size=30, required=True),<br /> 'employee_id' : fields.many2one('hr.employee', 'Employee', required=True),<br /> 'function' : fields.many2one('res.partner.function', 'Function'),<br /> }<br />hr_contract()<br />
如果添加一个字段要通过看它的current contract来检索员工,我们使用functional field。对象hr_employee这样继承:
<br />class hr_employee(osv.osv):<br /> _name = "hr.employee"<br /> _description = "Employee"<br /> _inherit = "hr.employee"<br /> _columns = {<br /> 'contract_ids' : fields.one2many('hr.contract', 'employee_id', 'Contracts'),<br /> 'function' : fields.function(<br /> _get_cur_function_id,<br /> type='many2one',<br /> obj="res.partner.function",<br /> method=True,<br /> string='Contract Function'),<br /> }<br />hr_employee()<br />
这里有三个[color=red]note[/color]:
[list type=decimal]
[li]type =’many2one’是因为function field 必须生成一个一个many2one field;function is declared as a many2one in hr_contract also.[/li]
[li]obj =”res.partner.function” is used to specify that the object to use for the many2one field is res.partner.function.[/li]
[li]We called our method _get_cur_function_id because its role is to return a dictionary whose keys are ids of employees, and whose corresponding values are ids of the function of those employees. The code of this method is:[/li]
[/list]
<br />def _get_cur_function_id(self, cr, uid, ids, field_name, arg, context):<br /> for i in ids:<br /> #get the id of the current function of the employee of identifier "i"<br /> sql_req= """<br /> SELECT f.id AS func_id<br /> FROM hr_contract c<br /> LEFT JOIN res_partner_function f ON (f.id = c.function)<br /> WHERE<br /> (c.employee_id = %d)<br /> """ % (i,)<br /><br /> cr.execute(sql_req)<br /> sql_res = cr.dictfetchone()<br /><br /> if sql_res: #The employee has one associated contract<br /> res[i] = sql_res['func_id']<br /> else:<br /> #res[i] must be set to False and not to None because of XML:RPC<br /> # "cannot marshal None unless allow_none is enabled"<br /> res[i] = False<br /> return res<br />
[size=12pt][color=red]这是官方的文档,有的地方我做了小小的翻译,有的地方我怕翻译错了给帮助我的人带来不便。我主要是三个note不是很理解原理也不清晰,希望版主或者哪位大哥今天心情舒爽,能够指点指点!谢谢![/color][/size]
[/quote]
请问怎么返回html类型??并且在视图内显示出来。。。返回的html是img