字段(Fields) 简介
对象包括不同类型的字段,分为三类:simple types,relation types,functional fields。simple types是integers, floats, booleans, strings, etc …;relation types是表示对象间的关系(one2one, one2many, many2one)。Functional fields是特殊的字段,因为它们不是存储在数据库中,而是实时计算视图给定的其他字段。
这是OpenERP继承类方法初始化的头文件。(Here’s the header of the initialization method of the class any field defined in OpenERP inherits)。:
def __init__(self, string='unknown', required=False, readonly=False,
domain=None, context="", states=None, priority=0, change_default=False, size=None,
ondelete="set null", translate=False, select=False, **args) :
这里有一套通用的可选参数,它对大多数的字段类型是可用的:
change_default: | 别的字段的缺省值是否可依赖于本字段。这些缺省值定义在ir.values表格中。 |
---|---|
help: | 用于描述这个字段如何使用:更长的描述文字。当鼠标滑过该字段时将会显示在一个提示框中。 |
ondelete: | 如何处理相关记录的删除。允许的值有:‘restrict’, ‘no action’, ‘cascade’, ‘set null’, and ‘set default’。 |
priority: | Not used? |
readonly: | 当值为True时,该字段只读不可修改,缺省值:False |
required: | 当值为True时,在对象存储前,该字段必须有个值,缺省值:False |
size: | 数据库中该字段的size:number characters or digits. |
states: | 让我们为这个对象特定的states重写其他参数,Accepts a dictionary with the state names as keys and a list of name/value tuples as the values. For example: states={‘posted’:[(‘readonly’,True)]} |
string: | The field name as it should appear in a label or column header. Strings containing non-ASCII characters must use python unicode objects. For example: ‘tested’: fields.boolean(u’Testé’) |
translate: | 值为True的话应该翻译这个字段的content,为False的话就不翻。 |
对于一些字段类型,下面也是可选的参数:
context: | Define a variable’s value visible in the view’s context or an on-change function. Used when searching child table of one2many relationship? |
---|---|
domain: | 相关字段的Domain restriction 缺省值: []. 示例: domain=[(‘field’,’=’,value)]) |
invisible: | 在表单中隐藏该字段的值,例如输入密码区 |
on_change: | Default value for the on_change attribute in the view. This will launch a function on the server when the field changes in the client. For example, on_change=”onchange_shop_id(shop_id)”. |
relation: | 当某个字段是另张表的id reference时就使用它。This is the name of the table to look in. Most commonly used with related and function field types. |
select: | 视图中select 属性的默认值,1指basic search,2指advanced search. |