problems with inheritance
Lorenzo Gil Sanchez <[email protected]> Tue, 17 Aug 2004 14:01:35 +0200
| Newsgroups | gmane.comp.python.modeling |
|---|---|
| Message-ID | <[email protected]> |
I have a pymodel written in a file and after creating the database and
the python classes (mdl_generate_DB_schema.py and
mdl_generate_python_code -B) I try to run some basic code and I get this
exception:
Traceback (most recent call last):
File "model_person.py", line 33, in ?
from Person.Customer import Customer
File "/home/lgs/proyectos/pruebas-modeling/Person/Customer.py", line
2, in ?
from MDL.Customer import Customer as MDL_Customer_Customer
File "/home/lgs/proyectos/pruebas-modeling/Person/MDL/Customer.py",
line 5, in ?
from Person.Person import Person
ImportError: No module named Person
It looks like the problem arises when using Inheritance. In my model,
the Customer entity inherits from the Person entity. The python code
generated by modeling tryies to import Person when defining Customer and
it can't find it.
I think a possible solution would be to modify the __init__.py file of
the package modeling is generating so it imports all the domain classes
generated.
Here is my pymodel and test file:
from Modeling.PyModel import *
Attribute.defaults['usedForLocking']=1
AString.defaults['externalType']='TEXT'
AString.defaults['width'] = 0
AString.defaults['usedForLocking']=1
Association.defaults['delete']=['nullify', 'nullify']
Entity.defaults['properties'] = [
APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK')
]
_connDict = {'database': 'people.sqlite'}
model = Model('Person', adaptorName='SQLite', connDict=_connDict,
version='0.1')
model.entities = [
Entity('Person',
properties = [AString('name'), AString('surname')],
),
Entity('Customer',
properties = [AString('phone')],
parent='Person',
)
]
model.build()
if __name__ == '__main__':
from Modeling.EditingContext import EditingContext
from Person.Person import Person
from Person.Customer import Customer
ec = EditingContext()
p = Person()
p.setName('Erny')
ec.insert(p)
c = Customer()
c.setName('Lorenzo')
c.setPhone('93923924')
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285