The second method makes use of the metaclass dynamic.CustomObjectMeta:
# file: Book.py # We assume that the model is already loaded from Modeling import dynamic class Book: __metaclass__=dynamic.CustomObjectMeta entityName='Book' mdl_define_properties=1 # your own code here
The metaclass CustomObjectMeta automatically adds all the necessary methods to a class for integration with the modeling framework. It looks for the following attributes in the class:
entityNamed
`: mandatory, this is the name of the class'
entity. The corresponding model should have been loaded prior to the class
declaration, or you'll get a dynamic.EntityNotFound exception.
verbose_metaclass
: if set, the metaclass prints on
sys.stderr
some info while building the class.
mdl_define_properties
: if set, the metaclass will also add
properties for each attribute on relationship in the entity.
Last, then dynamic module also offers a method
build_with_metaclass(model, define_properties=0, verbose=0) which you
can use to derive the necessary package and modules from a model just like
dynamic.build()
we saw above, the ony difference being that the classes
created at runtime use the metaclass approach.
Comments are welcome: Sebastien Bigaret / Modeling Home Page