2
.. i18n: .. _fields-link:
4
.. i18n: Fields Introduction
5
.. i18n: ===================
13
.. i18n: Objects may contain different types of fields. Those types can be divided into
14
.. i18n: three categories: simple types, relation types and functional fields. The
15
.. i18n: simple types are integers, floats, booleans, strings, etc ... ; the relation
16
.. i18n: types are used to represent relations between objects (one2one, one2many,
17
.. i18n: many2one). Functional fields are special fields because they are not stored in
18
.. i18n: the database but calculated in real time given other fields of the view.
21
Objects may contain different types of fields. Those types can be divided into
22
three categories: simple types, relation types and functional fields. The
23
simple types are integers, floats, booleans, strings, etc ... ; the relation
24
types are used to represent relations between objects (one2one, one2many,
25
many2one). Functional fields are special fields because they are not stored in
26
the database but calculated in real time given other fields of the view.
28
.. i18n: Here's the header of the initialization method of the class any field defined
29
.. i18n: in OpenERP inherits (as you can see in server/bin/osv/fields.py)::
31
.. i18n: def __init__(self, string='unknown', required=False, readonly=False,
32
.. i18n: domain=None, context="", states=None, priority=0, change_default=False, size=None,
33
.. i18n: ondelete="set null", translate=False, select=False, **args) :
36
Here's the header of the initialization method of the class any field defined
37
in OpenERP inherits (as you can see in server/bin/osv/fields.py)::
39
def __init__(self, string='unknown', required=False, readonly=False,
40
domain=None, context="", states=None, priority=0, change_default=False, size=None,
41
ondelete="set null", translate=False, select=False, **args) :
43
.. i18n: There are a common set of optional parameters that are available to most field
47
There are a common set of optional parameters that are available to most field
50
.. i18n: :change_default:
51
.. i18n: Whether or not the user can define default values on other fields depending
52
.. i18n: on the value of this field. Those default values need to be defined in
53
.. i18n: the ir.values table.
55
.. i18n: A description of how the field should be used: longer and more descriptive
56
.. i18n: than `string`. It will appear in a tooltip when the mouse hovers over the
59
.. i18n: How to handle deletions in a related record. Allowable values are:
60
.. i18n: 'restrict', 'no action', 'cascade', 'set null', and 'set default'.
61
.. i18n: :priority: Not used?
62
.. i18n: :readonly: `True` if the user cannot edit this field, otherwise `False`.
64
.. i18n: `True` if this field must have a value before the object can be saved,
65
.. i18n: otherwise `False`.
66
.. i18n: :size: The size of the field in the database: number characters or digits.
68
.. i18n: Lets you override other parameters for specific states of this object.
69
.. i18n: Accepts a dictionary with the state names as keys and a list of name/value
70
.. i18n: tuples as the values. For example: `states={'posted':[('readonly',True)]}`
72
.. i18n: The field name as it should appear in a label or column header. Strings
73
.. i18n: containing non-ASCII characters must use python unicode objects.
74
.. i18n: For example: `'tested': fields.boolean(u'Testé')`
76
.. i18n: `True` if the *content* of this field should be translated, otherwise
81
Whether or not the user can define default values on other fields depending
82
on the value of this field. Those default values need to be defined in
85
A description of how the field should be used: longer and more descriptive
86
than `string`. It will appear in a tooltip when the mouse hovers over the
89
How to handle deletions in a related record. Allowable values are:
90
'restrict', 'no action', 'cascade', 'set null', and 'set default'.
92
:readonly: `True` if the user cannot edit this field, otherwise `False`.
94
`True` if this field must have a value before the object can be saved,
96
:size: The size of the field in the database: number characters or digits.
98
Lets you override other parameters for specific states of this object.
99
Accepts a dictionary with the state names as keys and a list of name/value
100
tuples as the values. For example: `states={'posted':[('readonly',True)]}`
102
The field name as it should appear in a label or column header. Strings
103
containing non-ASCII characters must use python unicode objects.
104
For example: `'tested': fields.boolean(u'Testé')`
106
`True` if the *content* of this field should be translated, otherwise
109
.. i18n: There are also some optional parameters that are specific to some field types:
112
There are also some optional parameters that are specific to some field types:
115
.. i18n: Define a variable's value visible in the view's context or an on-change
116
.. i18n: function. Used when searching child table of `one2many` relationship?
118
.. i18n: Domain restriction on a relational field.
122
Define a variable's value visible in the view's context or an on-change
123
function. Used when searching child table of `one2many` relationship?
125
Domain restriction on a relational field.
127
.. i18n: Default value: [].
132
.. i18n: Example: domain=[('field','=',value)])
133
.. i18n: :invisible: Hide the field's value in forms. For example, a password.
135
.. i18n: Default value for the `on_change` attribute in the view. This will launch
136
.. i18n: a function on the server when the field changes in the client. For example,
137
.. i18n: `on_change="onchange_shop_id(shop_id)"`.
139
.. i18n: Used when a field is an id reference to another table. This is the name of
140
.. i18n: the table to look in. Most commonly used with related and function field
143
.. i18n: Default value for the `select` attribute in the view. 1 means basic search,
144
.. i18n: and 2 means advanced search.
147
Example: domain=[('field','=',value)])
148
:invisible: Hide the field's value in forms. For example, a password.
150
Default value for the `on_change` attribute in the view. This will launch
151
a function on the server when the field changes in the client. For example,
152
`on_change="onchange_shop_id(shop_id)"`.
154
Used when a field is an id reference to another table. This is the name of
155
the table to look in. Most commonly used with related and function field
158
Default value for the `select` attribute in the view. 1 means basic search,
159
and 2 means advanced search.