我在odoo中创建一个模块,我想使用many2one作为选择字段,问题出在城市'ville en francais'的名称上,下拉菜单有效,并且保存了城市ID(来自数据库),但是名称类似于obj.ville,1(它显示模块的名称,而不是数据库中城市的名称)
class obj_ghotel(osv.osv):
_name = "obj.ghotel"
_description = "Objet ghotel"
def _get_selection(self, cr, uid, context = None):
ville_obj = self.pool.get('obj.ville')
ville_obj = self.env['obj.ville']
res = []
ville_ids = ville_obj.search(cr, uid, [], context = context)
for g in ville_obj.browse(cr, uid, ville_ids, context = context):
res.append((g.id, g.nom_ville))
return res
_columns = {
'nom_hotel': fields.char( "Nom d'hotel", required=True ),
'adr_hotel': fields.char( "Addresse hotel", required=True ),
'id_ville':fields.many2one('obj.ville','ville', selection=_get_selection), #fields.integer('Id Ville', required=True ), #Foreign key references ville(id) 'id_ville':fields.many2one('ville','ville'),
'image': fields.binary( "Image" ),
}
class obj_ville(osv.osv):
_name = "obj.ville"
_description = "Objet ville"
_columns = {
'nom_ville': fields.char( "Nom Ville", required=True ),
'id_hotel':fields.one2many('obj.ghotel','id_ville'),
}
_defaults = {
'Nom Ville': "Name",
}
最佳答案
您可以按以下方式使用_rec_name
:
酒店型号:
class obj_ghotel(osv.osv):
_name = "obj.ghotel"
_description = "Objet ghotel"
_rec_name = 'nom_hotel'
维尔模型:
class obj_ville(osv.osv):
_name = "obj.ville"
_description = "Objet ville"
_rec_name = 'nom_ville'