Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: doc/ref/models/fields.rst

Issue 907042: First snapshot of trytond documentation refactoring (Closed)
Left Patch Set: Fix last comments Created 14 years, 11 months ago
Right Patch Set: Fix last comments Created 14 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « doc/ref/index.rst ('k') | doc/ref/models/index.rst » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 .. _ref-models-fields: 1 .. _ref-models-fields:
2 .. module:: trytond.model.fields 2 .. module:: trytond.model.fields
3 3
4 ====== 4 ======
5 Fields 5 Fields
6 ====== 6 ======
7 7
8 Fields define the behaviors of the data on model's record. 8 Fields define the behavior of the data on model's record.
udono 2010/05/07 12:48:31 behavior
9 9
10 Field options 10 Field options
11 ============= 11 =============
12 12
13 The following arguments are available to all field types. All are optional 13 The following arguments are available to all field types. All are optional
14 except :attr:`Field.string`. 14 except :attr:`Field.string`.
15 15
16 ``string`` 16 ``string``
17 ---------- 17 ----------
18 18
(...skipping 23 matching lines...) Expand all
42 If ``True``, the field is not editable in the client. Default is ``False``. 42 If ``True``, the field is not editable in the client. Default is ``False``.
43 43
44 ``domain`` 44 ``domain``
45 ---------- 45 ----------
46 46
47 .. attribute:: Field.domain 47 .. attribute:: Field.domain
48 48
49 A :ref:`domain <topics-domain>` constraint that will be applied on the field 49 A :ref:`domain <topics-domain>` constraint that will be applied on the field
50 value. 50 value.
51 51
52 .. warning:: 52 .. warning::
udono 2010/05/07 12:48:31 .. note:: ?
53 53
54 For now it only works on relational fields like :class:`Many2One`, 54 For now it only works on relational fields like :class:`Many2One`,
55 :class:`One2Many` and :class:`Many2Many`. 55 :class:`One2Many` and :class:`Many2Many`.
56 .. 56 ..
57 57
58 ``states`` 58 ``states``
59 ---------- 59 ----------
60 60
61 .. attribute:: Field.states 61 .. attribute:: Field.states
62 62
63 A dictionary that defines dynamic states of the field and overrides the static 63 A dictionary that defines dynamic states of the field and overrides the static
64 one. Possible keys are ``required``, ``readonly`` and ``invisible``. 64 one. Possible keys are ``required``, ``readonly`` and ``invisible``.
65 The values are :class:`~trytond.pyson.PYSON` statements that will be evaluated 65 The values are :class:`~trytond.pyson.PYSON` statements that will be evaluated
66 with the record values. 66 with the values of the record.
udono 2010/05/07 12:48:31 with the values of the record.
67 67
68 ``priority`` 68 ``priority``
69 ------------ 69 ------------
70 70
71 .. attribute:: Field.priority 71 .. attribute:: Field.priority
72 72
73 Give the order in which setter methods (if exist) are called on a model. 73 Give the order in which setter methods (if exist) are called on a model.
udono 2010/05/07 12:48:31 An integer, which give... Default is 0. Lower prio
74 Default is 0. Lower priority called first.
74 75
75 ``change_default`` 76 ``change_default``
76 ------------------ 77 ------------------
77 78
78 .. attribute:: Field.change_default 79 .. attribute:: Field.change_default
79 80
80 If true, the field can be used as condition for a custom default value. 81 If true, the field can be used as condition for a custom default value.
81 82
82 ``select`` 83 ``select``
83 ---------- 84 ----------
84 85
85 .. attribute:: Field.select 86 .. attribute:: Field.select
86 87
87 When equal to ``1``, the field appears in the search box in list view and the 88 When equal to ``1``, the field appears in the search box in list view and the
88 search will be optimized. When equal to ``2`` the field appears in the 89 search will be optimized. When equal to ``2`` the field appears in the
89 *Advanced Search* in the search box. 90 *Advanced Search* in the search box.
90 91
91 ``on_change`` 92 ``on_change``
92 ------------- 93 -------------
93 94
94 .. attribute:: Field.on_change 95 .. attribute:: Field.on_change
95 96
96 A list of field names, if this attribute is set, the client will call the 97 A list of field names. If this attribute is set, the client will call the
udono 2010/05/07 12:48:31 ... names. If ...
97 method ``on_change_<field name>`` of the model when the user changes the 98 method ``on_change_<field name>`` of the model when the user changes the
98 current field value and will give the values of each fields in this list. The 99 current field value and will give the values of each fields in this list. The
99 method signature is:: 100 method signature is::
100 101
101 on_change_<field name>(cursor, user, values[, context]) 102 on_change_<field name>(cursor, user, values[, context])
102 103
103 It must return a dictionary with the values of fields that must be updated. 104 This method must return a dictionary with the values of fields to be updated.
udono 2010/05/07 12:48:31 This method need to return a dictionary with the v
104 105
105 .. note:: 106 .. note::
106 107
107 The on_change_<field name> methods are runnin in a rollbacked transaction. 108 The on_change_<field name> methods are runnin in a rollbacked transaction.
108 .. 109 ..
109 110
110 ``on_change_with`` 111 ``on_change_with``
111 ------------------ 112 ------------------
112 113
113 .. attribute:: Field.on_change_with 114 .. attribute:: Field.on_change_with
114 115
115 A list of field names, like :attr:`on_change`, but defined the other way 116 A list of field names. Same like :attr:`on_change`, but defined the other way
udono 2010/05/07 12:48:31 ... names. Same like...
116 around. If this attribute is set, the client will call the method 117 around. If this attribute is set, the client will call the method
117 ``on_change_with_<field name>`` of the model when the user changes one of the 118 ``on_change_with_<field name>`` of the model when the user changes one of the
118 fields defined in the list and will give the values of each fields in this list. 119 fields defined in the list and will give the values of each fields in this
119 The method signature is:: 120 list. The method signature is::
120 121
121 on_change_with_<field name>(cursor, user, values[, context]) 122 on_change_with_<field name>(cursor, user, values[, context])
122 123
123 It must return the new value of the field. 124 This method must return the new value of the field.
udono 2010/05/07 12:48:31 This method need to return the new value of the fi
124 125
125 .. note:: 126 .. note::
126 127
127 The on_change_with_<field name> methods are running in a rollbacked transact ion. 128 The on_change_with_<field name> methods are running in a rollbacked transact ion.
128 129
129 .. 130 ..
130 131
131 ``depends`` 132 ``depends``
132 ----------- 133 -----------
133 134
134 .. attribute:: Field.depends 135 .. attribute:: Field.depends
135 136
136 A list of field names on which the current one depends. This means that the 137 A list of field names on which the current one depends. This means that the
137 client will also read those fields even if they are not defined on the view. 138 client will also read these fields even if they are not defined on the view.
udono 2010/05/07 12:48:31 those->these?
138 :attr:`Field.depends` is used per example to ensure that 139 :attr:`Field.depends` is used per example to ensure that
139 :class:`~trytond.pyson.PYSON` statement could be evaluated. 140 :class:`~trytond.pyson.PYSON` statement could be evaluated.
140 141
141 ``order_field`` 142 ``order_field``
142 --------------- 143 ---------------
143 144
144 .. attribute:: Field.order_field 145 .. attribute:: Field.order_field
145 146
146 The name of a substitute field on which the ordering of record must be done 147 The name of a substitute field on which the ordering of records must be done
udono 2010/05/07 12:48:31 ordering of records
147 instead of this one. 148 instead of this one.
148 This is often used to allow ordering on :class:`Function` fields. 149 This is often used to allow ordering on :class:`Function` fields.
149 150
150 ``context`` 151 ``context``
151 ----------- 152 -----------
152 153
153 .. attribute:: Field.context 154 .. attribute:: Field.context
154 155
155 A dictionary which will update the current context when opening a *relation 156 A dictionary which will update the current context when opening a *relation
156 field*. 157 field*.
(...skipping 26 matching lines...) Expand all
183 ---- 184 ----
184 185
185 .. class:: Char(string[, size[, translate[, \**options]]]) 186 .. class:: Char(string[, size[, translate[, \**options]]])
186 187
187 A single line string field. 188 A single line string field.
188 189
189 :class:`Char` has two extra optional arguments: 190 :class:`Char` has two extra optional arguments:
190 191
191 .. attribute:: Char.size 192 .. attribute:: Char.size
192 193
193 The maximum length (in characters) of the field. The size is enforced at 194 The maximum length (in characters) of the field. The size is enforced at
udono 2010/05/07 12:48:31 An integer, which defines the maximum count of cha
194 the storage level and in the client input. 195 the storage level and in the client input.
195 196
196 .. attribute:: Char.translate 197 .. attribute:: Char.translate
197 198
198 If true, the value of the field is translatable. The value readed and 199 If true, the value of the field is translatable. The value readed and
199 stored will depend on the ``language`` defined in the context. 200 stored will depend on the ``language`` defined in the context.
200 201
201 Sha 202 Sha
202 --- 203 ---
203 204
(...skipping 25 matching lines...) Expand all
229 230
230 .. class:: Float(string[, digits[, \**options]]) 231 .. class:: Float(string[, digits[, \**options]])
231 232
232 A floating-point number field. It will be represented in Python by a ``float`` 233 A floating-point number field. It will be represented in Python by a ``float``
233 instance. 234 instance.
234 235
235 :class:`Float` has one extra optional arguments: 236 :class:`Float` has one extra optional arguments:
236 237
237 .. attribute:: Float.digits 238 .. attribute:: Float.digits
238 239
239 A tuple of two integers defining the total of numbers in integer part and 240 A tuple of two integers. The first integer defines the total of numbers in
udono 2010/05/07 12:48:31 A tuple of two integers. The first integer defines
240 the number of decimals. 241 the integer part. The second integer defines the total of numbers in the
242 decimal part.
241 Integers can be replaced by a :class:`~trytond.pyson.PYSON` statement. 243 Integers can be replaced by a :class:`~trytond.pyson.PYSON` statement.
242 244
243 Numeric 245 Numeric
244 ------- 246 -------
245 247
246 .. class:: Numeric(string[, digits[, \**options]]) 248 .. class:: Numeric(string[, digits[, \**options]])
247 249
248 A fixed-point number field. It will be represented in Python by a 250 A fixed-point number field. It will be represented in Python by a
249 ``decimal.Decimal`` instance. 251 ``decimal.Decimal`` instance.
250 252
(...skipping 29 matching lines...) Expand all
280 282
281 .. class:: Binary(string[, \**options]) 283 .. class:: Binary(string[, \**options])
282 284
283 A binary field. It will be represented in Python by a ``str`` instance. 285 A binary field. It will be represented in Python by a ``str`` instance.
284 286
285 Selection 287 Selection
286 --------- 288 ---------
287 289
288 .. class:: Selection(selection, string[, sort[, translate[, \**options]]]) 290 .. class:: Selection(selection, string[, sort[, translate[, \**options]]])
289 291
290 A string field with limited choice values. 292 A string field with limited values to choice.
udono 2010/05/07 12:48:31 choice values-> values to choice
291 293
292 :class:`Selection` has one extra required argument: 294 :class:`Selection` has one extra required argument:
293 295
294 .. attribute:: Selection.selection 296 .. attribute:: Selection.selection
295 297
296 A list of 2-tuples that looks like this:: 298 A list of 2-tuples that looks like this::
297 299
298 [ 300 [
299 ('M', 'Male'), 301 ('M', 'Male'),
300 ('F', 'Female'), 302 ('F', 'Female'),
301 ] 303 ]
302 304
303 The first element in each tuple is the actual value stored. The second 305 The first element in each tuple is the actual value stored. The second
304 element is the human-readable name. 306 element is the human-readable name.
305 307
306 It can also be the name of a method on the model, that will return the 308 It can also be the name of a method on the model, that will return an
udono 2010/05/07 12:48:31 ...return an appropriate list.
307 list. The signature of the method is:: 309 appropriate list. The signature of the method is::
308 310
309 selection(cursor, user[, context]) 311 selection(cursor, user[, context])
310 312
311 .. note:: 313 .. note::
312 The method is automaticly added to :attr:`trytond.model.Model._rpc` if 314 The method is automaticly added to :attr:`trytond.model.Model._rpc` if
313 not manually set. 315 not manually set.
314 .. 316 ..
315 317
316 :class:`Selection` has two extra optional arguments: 318 :class:`Selection` has two extra optional arguments:
317 319
318 .. attribute:: Selection.sort 320 .. attribute:: Selection.sort
319 321
320 If true, the choices will be sorted by human-readable value. Default value 322 If true, the choices will be sorted by human-readable value. Default value
321 is ``True``. 323 is ``True``.
322 324
323 .. attribute:: Selection.translate_selection 325 .. attribute:: Selection.translate_selection
324 326
325 It true, the human-readable values will be translated. Default value is 327 If true, the human-readable values will be translated. Default value is
udono 2010/05/07 12:48:31 It->If
326 ``True``. 328 ``True``.
327 329
328 Reference 330 Reference
329 --------- 331 ---------
330 332
331 .. class:: Reference(string[, selection[, \**options]]) 333 .. class:: Reference(string[, selection[, \**options]])
332 334
333 A field that refers to a record of a model. It will be represented in Python by 335 A field that refers to a record of a model. It will be represented in Python by
334 a ``str`` instance like this:: 336 a ``str`` instance like this::
335 337
336 '<model name>,<record id>' 338 '<model name>,<record id>'
337 339
338 :class:`Reference` has one extra optional argument: 340 :class:`Reference` has one extra optional argument:
339 341
340 .. attribute:: Reference.selection 342 .. attribute:: Reference.selection
341 343
342 Same as :attr:`Selection.selection` but only for model name. 344 Same as :attr:`Selection.selection` but only for model name.
343 345
344 Many2One 346 Many2One
345 -------- 347 --------
346 348
347 .. class:: Many2One(model_name, string[, left[, right[, ondelete[, datetime_fiel d[, \**options]]]]]) 349 .. class:: Many2One(model_name, string[, left[, right[, ondelete[, datetime_fiel d[, \**options]]]]])
348 350
349 A many-to-one relation field. 351 A many-to-one relation field.
350 352
351 :class:`Many2One` has one extra required argument: 353 :class:`Many2One` has one extra required argument:
352 354
353 .. attribute:: Many2One.model_name 355 .. attribute:: Many2One.model_name
354 356
355 The name of the targeted model. 357 The name of the target model.
udono 2010/05/07 12:48:31 target model
356 358
357 :class:`Many2One` has some extra optional arguments: 359 :class:`Many2One` has some extra optional arguments:
358 360
359 .. attribute:: Many2One.left 361 .. attribute:: Many2One.left
360 362
361 The name of the field that stores the left value for the `Modified Preorder 363 The name of the field that stores the left value for the `Modified Preorder
362 Tree Traversal`_. 364 Tree Traversal`_.
363 It only works if the :attr:`model_name` is the same then the model. 365 It only works if the :attr:`model_name` is the same then the model.
364 366
365 .. _`Modified Preorder Tree Traversal`: http://en.wikipedia.org/wiki/Tree_traver sal 367 .. _`Modified Preorder Tree Traversal`: http://en.wikipedia.org/wiki/Tree_traver sal
366 368
367 .. attribute:: Many2One.right 369 .. attribute:: Many2One.right
368 370
369 The name of the field that stores the right value. See :attr:`left`. 371 The name of the field that stores the right value. See :attr:`left`.
370 372
371 .. attribute:: Many2One.ondelete 373 .. attribute:: Many2One.ondelete
372 374
373 Define the behavior of the record when the target record is deleted. 375 Define the behavior of the record when the target record is deleted.
udono 2010/05/07 12:48:31 current record
374 Allowed values are: 376 Allowed values are:
375 377
376 - ``CASCADE``: it will try to delete the record. 378 - ``CASCADE``: it will try to delete the record.
377 379
378 - ``RESTRICT``: it will prevent the deletion of the target record. 380 - ``RESTRICT``: it will prevent the deletion of the target record.
379 381
380 - ``SET NULL``: it will empty the relation field. 382 - ``SET NULL``: it will empty the relation field.
udono 2010/05/07 12:48:31 ``SET NULL`` is the default setting.
383
384 ``SET NULL`` is the default setting.
381 385
382 .. note:: 386 .. note::
383 ``SET NULL`` will be override into ``RESTRICT`` if 387 ``SET NULL`` will be override into ``RESTRICT`` if
384 :attr:`~Field.required` is true. 388 :attr:`~Field.required` is true.
385 .. 389 ..
386 390
387 .. attribute:: Many2One.datetime_field 391 .. attribute:: Many2One.datetime_field
388 392
389 If set, the target record will be read at the date defined by the datetime 393 If set, the target record will be read at the date defined by the datetime
390 field name of the record. 394 field name of the record.
(...skipping 27 matching lines...) Expand all
418 record. 422 record.
419 423
420 - ``('unlink_all')``: it will unlink all the target records. 424 - ``('unlink_all')``: it will unlink all the target records.
421 425
422 - ``('set'[, ids, ...])``: it will link only the target ids to this record. 426 - ``('set'[, ids, ...])``: it will link only the target ids to this record.
423 427
424 :class:`One2Many` has some extra required arguments: 428 :class:`One2Many` has some extra required arguments:
425 429
426 .. attribute:: One2Many.model_name 430 .. attribute:: One2Many.model_name
427 431
428 The name of the targeted model. 432 The name of the target model.
udono 2010/05/07 12:48:31 target
429 433
430 .. attribute:: One2Many.field 434 .. attribute:: One2Many.field
431 435
432 The name of the field that handles the opposite :class:`Many2One` 436 The name of the field that handles the opposite :class:`Many2One`
433 437
434 :class:`One2Many` has some extra optional arguments: 438 :class:`One2Many` has some extra optional arguments:
435 439
436 .. attribute:: One2Many.add_remove 440 .. attribute:: One2Many.add_remove
437 441
438 A :ref:`domain <topics-domain>` to select records to add. If set, the 442 A :ref:`domain <topics-domain>` to select records to add. If set, the
(...skipping 24 matching lines...) Expand all
463 467
464 .. attribute:: Many2Many.origin 468 .. attribute:: Many2Many.origin
465 469
466 The name of the field that has the :class:`Many2One` to the record. 470 The name of the field that has the :class:`Many2One` to the record.
467 471
468 .. attribute:: Many2Many.target 472 .. attribute:: Many2Many.target
469 473
470 The name of the field that has the :class:`Many2One` to the target record. 474 The name of the field that has the :class:`Many2One` to the target record.
471 475
472 .. note:: 476 .. note::
473 For :class:`Many2Many` field on simple :class:`~trytond.model.ModelView`, 477 A :class:`Many2Many` field can be used on a simple
474 like used in :class:`~trytond.wizard.Wizard`, 478 :class:`~trytond.model.ModelView`, like in a
475 :attr:`~Many2Many.relation_name` is set to the target model and 479 :class:`~trytond.wizard.Wizard`. For this, :attr:`~Many2Many.relation_name`
476 :attr:`~Many2Many.origin` and :attr:`~Many2Many.target` are set to `None`. 480 is set to the target model and :attr:`~Many2Many.origin` and
udono 2010/05/07 12:48:31 Sentence complicated. Maybe: A :class:`Many2Many`
481 :attr:`~Many2Many.target` are set to `None`.
477 .. 482 ..
478 483
479 :class:`Many2Many` has some extra optional arguments: 484 :class:`Many2Many` has some extra optional arguments:
480 485
481 .. attribute:: Many2Many.order 486 .. attribute:: Many2Many.order
482 487
483 Same as :attr:`One2Many.order` 488 Same as :attr:`One2Many.order`
484 489
485 .. attribute:: Many2Many.datetime_field 490 .. attribute:: Many2Many.datetime_field
486 491
487 Same as :attr:`Many2One.datetime_field` 492 Same as :attr:`Many2One.datetime_field`
488 493
489 Instance methods: 494 Instance methods:
490 495
491 .. method:: Many2Many.get_target(pool) 496 .. method:: Many2Many.get_target(pool)
492 497
493 Return the target :class:`~trytond.model.Model`. 498 Return the target :class:`~trytond.model.Model`.
494 499
495 Function 500 Function
496 -------- 501 --------
497 502
498 .. class:: Function(field, getter[, setter[, searcher]]) 503 .. class:: Function(field, getter[, setter[, searcher]])
499 504
500 A function field that can emulate any other given `field`. 505 A function field can emulate any other given `field`.
udono 2010/05/07 12:48:31 ...field can emulate...
501 506
502 :class:`Function` has a required argument: 507 :class:`Function` has a required argument:
503 508
504 .. attribute:: Function.getter 509 .. attribute:: Function.getter
505 510
506 The name of the classmethod of the :class:`~trytond.model.Model` for 511 The name of the classmethod of the :class:`~trytond.model.Model` for
507 getting values. 512 getting values.
508 The signature of the method is:: 513 The signature of the method is::
509 514
510 getter(cursor, user, ids, name[, context]) 515 getter(cursor, user, ids, name[, context])
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 584
580 Same as :meth:`Function.get`. 585 Same as :meth:`Function.get`.
581 586
582 .. method:: Property.set(cursor, user, ids, model, name, value[, context]) 587 .. method:: Property.set(cursor, user, ids, model, name, value[, context])
583 588
584 Same as :meth:`Function.set`. 589 Same as :meth:`Function.set`.
585 590
586 .. method:: Property.search(cursor, user, model, name, clause[, context]) 591 .. method:: Property.search(cursor, user, model, name, clause[, context])
587 592
588 Same as :meth:`Function.search`. 593 Same as :meth:`Function.search`.
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b