### Navigation

- index
- modules |
- next |
- previous |
- trytond 3.0 documentation »
- Using trytond »

# 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 `trytond.model.model.Model`.
> - Fields are defined as model attributes.
> - Tryton generates the table definitions
> - Tryton provides an API following the active record pattern to access the records.

## 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 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.

### Navigation

- index
- modules |
- next |
- previous |
- trytond 3.0 documentation »
- Using trytond »