Files
tryton/trytond/doc/topics/models/fields_default_value.rst
T

39 lines
840 B
ReStructuredText
Raw Normal View History

.. _topics-fields_default_value:
=======================
Default value of fields
=======================
When a record is created, each field, which doesn't have a value specified,
is set with the default value if exists.
2022-03-27 16:06:09 +02:00
The following class method:
2023-03-15 16:33:19 +01:00
.. rstcheck: ignore-next-code-block
2022-03-27 16:06:09 +02:00
.. code-block:: python
Model.default_<field name>()
Return the default value for ``field name``.
2022-03-27 16:06:09 +02:00
This example defines an ``Item`` model which has a default ``since``:
.. code-block:: python
import datetime
from trytond.model import ModelView, ModelSQL, fields
2022-03-27 16:06:09 +02:00
class Item(ModelSQL, ModelView):
"Item"
__name__ = 'item'
since = fields.Date('since')
@classmethod
def default_since(cls):
return datetime.date.today()
2022-03-27 16:06:09 +02:00
See also method :meth:`~trytond.model.Model.default_get`.