File: fields_default_value.rst

package info (click to toggle)
tryton-server 3.4.0-3%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 4,600 kB
  • ctags: 3,933
  • sloc: python: 28,679; xml: 3,996; sql: 328; sh: 150; makefile: 82
file content (31 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.. _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.

The following class method::

    Model.default_<field name>()

Return the default value for ``field name``.

This example defines an ``Item`` model which has a default ``since``::

    import datetime

    from trytond.model import ModelView, ModelSQL, fields

    class Item(ModelSQL, ModelView):
        "Item"
        __name__ = 'item'
        since = fields.Date('since')

        @classmethod
        def default_since(cls):
            return datetime.date.today()

See also method ``Model.default_get``: :attr:`~trytond.model.Model.default_get`