File: index.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 (47 lines) | stat: -rw-r--r-- 1,368 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.. _topics-models:

======
Models
======

A model represents a single business logic or concept. It contains fields and
defines the behaviors of the record. Most of the time, each model stores record
in a single database table.

The basics:

    * Each model is a Python class that subclasses one of
      :class:`trytond.model.model.Model`.

    * :ref:`Fields <ref-models-fields>` are defined as model attributes.

    * Tryton generates the table definitions

    * Tryton provides an API following the `active record pattern`_ to access the records.

.. _active record pattern: http://en.wikipedia.org/wiki/Active_record

Example
=======

This example defines a ``Party`` model which has a ``name`` and a ``code``
fields::

    from trytond.model import ModelView, ModelSQL, fields
    from trytond.pool import Pool

    class Party(ModelSQL, ModelView):
        "Party"
        __name__ = "party.party"
        name = fields.Char('Name')
        code = fields.Char('Code')

    Pool.register(Party)

The class must be registered in the :ref:`Pool <ref-pool>`.
Model classes are essentially data mappers to records and Model instances are
records.

Model attributes define meta-information of the model. They are class
attributes starting with an underscore.  Some model properties are instance
attributes allowing to update them at other places in the framework.