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.
If true, the field can be used as condition for a custom default value.
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>(values)
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>(values)
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.
A single line string field.
Char has two extra optional arguments:
The maximum length (in characters) of the field. The size is enforced at the storage level and in the client input.
If true, the value of the field is translatable. The value readed and stored will depend on the language defined in the context.
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.
Warning
Note that you may need to set Field.loading to lazy when Char.translate is True.
A string field which value will be stored with a secure hash algorithm.
A multi line string field.
Text has two extra optional arguments:
Same as Char.translate
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:
Same as Float.digits
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:
If true, the choices will be sorted by human-readable value. Default value is True.
If true, the human-readable values will be translated. Default value is True.
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>'
Reference has one extra optional argument:
Same as Selection.selection but only for model name.
A many-to-one relation field.
Many2One has one extra required argument:
The name of the target model.
Many2One has some extra optional arguments:
The name of the field that stores the left value for the Modified Preorder Tree Traversal. It only works if the model_name is the same then the model.
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.
If set, the target record will be read at the date defined by the datetime field name of the record. It is usually used in combination with trytond.model.ModelSQL._history to request a value for a given date and time on a historicized model.
A one-to-many relation field. It requires to have the opposite Many2One 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:
The name of the target model.
One2Many has some extra optional arguments:
A domain to select records to add. If set, the client will allow to add/remove existing records instead of only create/delete.
A list of tuple defining the default order of the records like for trytond.model.ModelSQL._order.
Same as Many2One.datetime_field
A many-to-many relation field.
Many2Many has some extra required arguments:
The name of the relation model.
Many2Many has some extra optional arguments:
Same as One2Many.order
Same as Many2One.datetime_field
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.
Same as Many2One.datetime_field
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:
Call the getter classmethod where model is the Model instance of the field, name is the name of the field.
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:
Same as Function.get().
Same as Function.set().
Same as Function.search().