~crass/tryton/server

« back to all changes in this revision

Viewing changes to doc/ref/models/fields.rst

  • Committer: Mathias Behrle
  • Date: 2013-11-24 16:28:54 UTC
  • Revision ID: git-v1:182d6cce169eab1682eeacbad4323efa1136a1a0
MergingĀ upstreamĀ versionĀ 3.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
:attr:`Field.depends` is used per example to ensure that
123
123
:class:`~trytond.pyson.PYSON` statement could be evaluated.
124
124
 
125
 
``order_field``
126
 
---------------
127
 
 
128
 
.. attribute:: Field.order_field
129
 
 
130
 
The name of a substitute field on which the ordering of records must be done
131
 
instead of this one.
132
 
This is often used to allow ordering on :class:`Function` fields.
133
 
 
134
125
``context``
135
126
-----------
136
127
 
153
144
 
154
145
The name of the field.
155
146
 
 
147
Instance methods:
 
148
 
 
149
.. method:: Field.convert_domain(domain, tables, Model)
 
150
 
 
151
    Convert the simple :ref:`domain <topics-domain>` clause into a SQL
 
152
    expression or a new domain.
 
153
 
 
154
Where ``tables`` is a nested dictionary containing the existing joins (and it
 
155
could be updated to add new joins)::
 
156
 
 
157
    {
 
158
        None: (<Table invoice>, None),
 
159
        'party': {
 
160
            None: (<Table party>, <join_on sql expression>),
 
161
            'addresses': {
 
162
                None: (<Table address>, <join_on sql expression>),
 
163
                },
 
164
            },
 
165
        }
 
166
 
 
167
.. method:: Field.sql_format(value)
 
168
 
 
169
    Convert the value to use as parameter of SQL queries.
 
170
 
 
171
.. method:: Field.sql_type()
 
172
 
 
173
    Return the namedtuple('SQLType', 'base type') which defines the SQL type to
 
174
    use for creation and casting.
 
175
 
156
176
Default value
157
177
=============
158
178
 
159
179
See :ref:`default value <topics-fields_default_value>`
160
180
 
 
181
Ordering
 
182
========
 
183
 
 
184
A class method could be defined for each field which must return a list of SQL
 
185
expression on which to order instead of the field.
 
186
The method signature is::
 
187
 
 
188
    order_<field name>(tables)
 
189
 
 
190
Where ``tables`` is a nested dictionary, see :meth:`~Field.convert_domain`.
 
191
 
161
192
Field types
162
193
===========
163
194
 
289
320
    the time part of the field. The default value is `%H:%M:%S`.
290
321
    The value can be replaced by a :class:`~trytond.pyson.PYSON` statement.
291
322
 
 
323
Timestamp
 
324
---------
 
325
 
 
326
.. class:: Timestamp(string[, \**options])
 
327
 
 
328
A timestamp, represented in Python by a ``datetime.datetime`` instance.
 
329
 
292
330
Time
293
331
----
294
332
 
307
345
 
308
346
A binary field. It will be represented in Python by a ``str`` instance.
309
347
 
 
348
:class:`Binary` has one extra optional argument:
 
349
 
 
350
.. attribute:: Binary.filename
 
351
 
 
352
    Name of the field that holds the data's filename. Default value
 
353
    is an empty string, which means the data has no filename (in this case, the
 
354
    filename is hidden, and the "Open" button is hidden when the widget is set
 
355
    to "image").
 
356
 
 
357
 
310
358
Selection
311
359
---------
312
360
 
625
673
 
626
674
    where `name` is the name of the field and `clause` is a
627
675
    :ref:`domain clause <topics-domain>`.
628
 
    It must return a list of :ref:`domain <topics-domain>` clauses.
 
676
    It must return a list of :ref:`domain <topics-domain>` clauses but the
 
677
    ``operand`` can be a SQL query.
629
678
 
630
679
Instance methods:
631
680