模块开发实例(Story 2)继承视图

__init__.py

import product_img

这里是初始化的时候需要模块里面的那些py文件,我这里是product_img.py。所以写import product_img

__terp__.py

 

{
 
"name"  : "simple_product_image" ,
 
"version"  : "1.0" ,
 
"depends"  : [ "product" ],
 
"init_xml"  : [],
 
"update_xml"  : [ "product_img_view.xml" ],
 
"installable"  : True ,
 
"active"  : False ,
 
"author"  : "Joshua" ,
 
}

这里的最重要的有

“depends”:就是需要依赖哪些module,我这里既然是继承product当然就是product了。

“update_xml”:就是这个模块需要的Xml。我写了个是product_img_view.xml

product_img.py

#!/usr/bin/python
from osv import osv, fields
class product_product(osv.osv):
     _name = 'product.product'
     _inherit = 'product.product'
     _description = 'Product'
     _columns = { 'pic' :fields.binary( 'Pic' ),
}
 
product_product()

这里是object的继承

_name=’product.product’._inherit = ‘product.product’

此名字可以在Administrators->Customization->Database Structure->Object查找,不过我建议还是直接进addon里面看product模块

_columns就是字段了

‘pic’:fields.binary(‘Pic’), ‘pic’是字段名,就是数据库里面存的字段,fields.binary就是图片在OE里面的字段类型,后面的’Pic’是在OE里面显示的名称。

product_img_view.xml

 

< openerp >
     < data >
         < record id = "product_img_view" model = "ir.ui.view" >
             < field name = "name" >product.normal.form</ field >
             < field name = "model" >product.product</ field >
             < field name = "type" >form</ field >
             < field name = "inherit_id" ref = "product.product_normal_form_view" />
             < field name = "arch" type = "xml" >
                 < field name = "name" position = "before" >
                     < field name = "pic" widget = "image" nolabel = "1" img_width = "300" img_height = "300" />
                 </ field >
             </ field >
         </ record >
     </ data >
</ openerp >

这里的格式其实都已经很固定的了。这里是view的继承

“id”代表的是这个view,唯一。

“name”就是你要继承的view的名字

“model”就是你要继承的view的object…

“ref”就是你要继承的view的id

<field name=”name” position=”before”>

这句是是你的元件插入的时用于定位的我这里的意思是插在name之前

<field name=”pic” widget=”image” nolabel=”1″ img_width=”300″ img_height=”300″/>

这句就是你所要插入的东西了,我这里是插入一个图片300*300大小的图片。

效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值