Add documentation for Model.default_<field name>
issue2594 review367001
This commit is contained in:
1 parent
9a25299e25
commit
cdd2cd6ecf
3 files changed
+40
No files matched your search
@@ -146,6 +146,11 @@ field*.
|
||||
|
||||
Define how the field must be loaded: ``lazy`` or ``eager``.
|
||||
|
||||
Default value
|
||||
=============
|
||||
|
||||
See :ref:`default value <topics-fields_default_value>`
|
||||
|
||||
Field types
|
||||
===========
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ Introduction to all the key parts of trytond:
|
||||
|
||||
install
|
||||
models/index
|
||||
models/fields_default_value
|
||||
domain
|
||||
pyson
|
||||
views/index
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
.. _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 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"
|
||||
_description = __doc__
|
||||
_name = "item.item"
|
||||
since = fields.Date('since')
|
||||
|
||||
def default_since(self):
|
||||
return datetime.date.today()
|
||||
|
||||
Item()
|
||||
|
||||
See also method ``Model.default_get``: :attr:`~trytond.model.Model.default_get`
|
||||
|
||||
Reference in new issue
Block a user