credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #04064
Re: [Question #185725]: Example code for many2one - problem
Question #185725 on OpenERP Server changed:
https://answers.launchpad.net/openobject-server/+question/185725
Status: Open => Answered
Serpent Consulting Services proposed the following answer:
Fernando,
Follow these things, the problem will be solved:
1. Never name any field in uppercase. All field names should be lower case.
2. State model should be defined earlier than city, because you refer it as a foreign key-many2one.
3. For city model, add _rec_name='cityname' as you don't have any field 'name' on it.
--
class city(osv.osv):
_name=''
_rec_name=Field
The error comes because the system does not find a field called 'name'
in city model.
The Following code will work for you.
"""
class state(osv.osv):
_name = 'state'
_columns = {
'name': fields.char('State name',size=32),
}
state()
class city(osv.osv):
_name = 'city'
_rec_name = "cityname"
_columns = {
'cityname': fields.char('City', size=32),
'state': fields.many2one('state','name'),
}
city()
"""
Hope it helps.
Thanks,
Serpent Consulting Services.
http://www.serpentcs.com
--
You received this question notification because you are a member of
OpenERP Framework Experts, which is an answer contact for OpenERP
Server.