The next step is to define Clio models. A Clio model is a class that is going to be mapped to a table by the SQLAlchemy ORM. A Clio model also has a number of special methods that can be used to drive the workflow process and that will be described later.
It is easy to create a Clio-based model, just subclass from clio.Model:
import clio
class Address(clio.Model):
pass
In many cases, a clio.Model needs to define its own __init__. This looks like this:
class Address(clio.Model):
def __init__(self, code, street, city, country):
super(Address, self).__init__(code)
self.street = street
self.city = city
self.country = country
Note that it is required to call the superclass and pass it the code.
After definining the tables and the model classes, we use the normal SQLAlchemy object relational mapper to map the classes to the tables:
from sqlalchemy.orm import mapper
mapper(Address, address_table)
This is standard SQLAlchemy, and we have seen everything needed to create a Clio-managed model. The situation becomes a bit more involved when we want to create relations between models.
The Clio table columns described earlier will exist on the mapped instances. The following properties are available: