Fields define the behavior of the data on model’s record.
The following arguments are available to all field types. All are optional except Field.string.
A dictionary that defines dynamic states of the field and overrides the static one. Possible keys are required, readonly and invisible. The values are PYSON statements that will be evaluated with the values of the record.
A list of field names. If this attribute is set, the client will call the method on_change_<field name> of the model when the user changes the current field value and will give the values of each fields in this list. The method signature is:
on_change_<field name>()
This method must return a dictionary with the values of fields to be updated.
Note
The on_change_<field name> methods are runnin in a rollbacked transaction.
A list of field names. Same like on_change, but defined the other way around. If this attribute is set, the client will call the method on_change_with_<field name> of the model when the user changes one of the fields defined in the list and will give the values of each fields in this list. The method signature is:
on_change_with_<field name>()
This method must return the new value of the field.
Note
The on_change_with_<field name> methods are running in a rollbacked transaction.
A list of field names on which the current one depends. This means that the client will also read these fields even if they are not defined on the view. Field.depends is used per example to ensure that PYSON statement could be evaluated.
The name of a substitute field on which the ordering of records must be done instead of this one. This is often used to allow ordering on Function fields.
See default value
A single line string field.
Char has two extra optional arguments:
A list of field names. If this attribute is set, the client will call the method autocomplete_<field name> of the model when the user changes one of those field value. The method signature is:
autocomplete_<field name>(values)
This method must return a list of string that will populate the ComboboxEntry in the client.
A string field which value will be stored with a secure hash algorithm.
A multi line string field.
Text has two extra optional arguments:
A floating-point number field. It will be represented in Python by a float instance.
Float has one extra optional arguments:
A fixed-point number field. It will be represented in Python by a decimal.Decimal instance.
Numeric has one extra optional arguments:
A date, represented in Python by a datetime.date instance.
A date and time, represented in Python by a datetime.datetime instance.
A time, represented in Python by a datetime.time instance.
A binary field. It will be represented in Python by a str instance.
A string field with limited values to choice.
Selection has one extra required argument:
A list of 2-tuples that looks like this:
[
('M', 'Male'),
('F', 'Female'),
]
The first element in each tuple is the actual value stored. The second element is the human-readable name.
It can also be the name of a method on the model, that will return an appropriate list. The signature of the method is:
selection()
Note
The method is automaticly added to trytond.model.Model._rpc if not manually set.
Selection has two extra optional arguments:
A field that refers to a record of a model. It will be represented in Python by a str instance like this:
'<model name>,<record id>'
But a tuple can be used to search or set value.
Reference has one extra optional argument:
A many-to-one relation field.
Many2One has one extra required argument:
Many2One has some extra optional arguments:
Define the behavior of the record when the target record is deleted. Allowed values are:
- CASCADE: it will try to delete the record.
- RESTRICT: it will prevent the deletion of the target record.
- SET NULL: it will empty the relation field.
SET NULL is the default setting.
Note
SET NULL will be override into RESTRICT if required is true.
A one-to-many relation field. It requires to have the opposite Many2One field or a Reference field defined on the target model.
This field accepts as written value a list of tuples like this:
- ('create', {<field name>: value, ...}): it will create a new target record and link it to this one.
- ('write'[, ids, ...], {<field name>: value, ...}): it will write values to target ids.
- ('delete'[, ids, ...]): it will delete the target ids.
- ('delete_all'): it will delete all the target records.
- ('add'[, ids, ...]): it will link the target ids to this record.
- ('unlink'[, ids, ...]): it will unlink the target ids from this record.
- ('unlink_all'): it will unlink all the target records.
- ('set'[, ids, ...]): it will link only the target ids to this record.
One2Many has some extra required arguments:
One2Many has some extra optional arguments:
A many-to-many relation field.
Many2Many has some extra required arguments:
Note
A Many2Many field can be used on a simple ModelView, like in a Wizard. For this, relation_name is set to the target model and origin and target are set to None.
Many2Many has some extra optional arguments:
Instance methods:
A one-to-one relation field.
Warning
It is on the relation_name Model that the unicity of the couple (origin, target) must be checked.
Instance methods:
A function field can emulate any other given field.
Function has a required argument:
The name of the classmethod of the Model for getting values. The signature of the method is:
getter(ids, name)
where name is the name of the field, and it must return a dictionary with a value for each ids.
Or the signature of the method is:
getter(ids, names)
where names is a list of name fields, and it must return a dictionary containing for each names a dictionary with a value for each ids.
Function has some extra optional arguments:
The name of the classmethod of the Model to set the value. The signature of the method id:
setter(ids, name, value)
where name is the name of the field and value the value to set.
The name of the classmethod of the Model to search on the field. The signature of the method is:
searcher(name, clause)
where name is the name of the field and clause is a domain clause. It must return a list of domain clauses.
Instance methods:
A property field that is like a Function field but with predifined getter, setter and searcher that use the ModelSQL ir.property to store values.
Instance methods: