Before dealing with all the details, here is an overview of a PyModel. Note the the id default property for entities, as well as the predefined Attribute sub-types, APrimaryKey and AString.
from Modeling.PyModel import * # Set preferred defaults for this model (when different from # standard defaults, or if we want to make things explicit) AFloat.defaults['precision'] = 10 AFloat.defaults['scale'] = 2 AString.defaults['width'] = 40 Association.defaults['delete']=['nullify', 'nullify'] Entity.defaults['properties'] = [ APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK') ] _connDict = {'database': 'AUTHOR_BOOKS'} model = Model('AuthorBooks',adaptorName='Postgresql', connDict=_connDict) model.version='0.1' model.entities = [ # Entity('Book', properties=[ AString('title', isRequired=1, columnName='title'), AFloat('price'), ], ), Entity('Writer', properties=[ AString('lastName',isRequired=1, width=30, displayLabel='Last Name', ), AString('firstName', displayLabel='First Name', ), AInteger('age', displayLabel='Age', ), ADateTime('birthday', usedForLocking=0, displayLabel='birthday', ), ] ), ] model.associations=[ Association('Book', 'Writer', relations=['author', 'books'], delete=['nullify', 'cascade']), Association('Writer', 'Writer', relations=['pygmalion', None], delete=['nullify', None]), ]
A PyModel is typically made of two parts: a first part sets the defaults, then
the second one defines the model. Defaults helps you keep the model definition
tidy, by removing the repetitive parts from the model definition itself; in
this example, the defaults add a primary key to each entity, sets the
width
for strings, etc.
Comments are welcome: Sebastien Bigaret / Modeling Home Page