If you need new name for all many2one('test.project.name')
in the system just override method name_get
. For your model it's will be like this(you use old API):
class TestProject(osv.Model):
_name = 'test.project.name'
def name_get(self, cr, uid, ids, context):
res = []
for record in self.browse(cr, uid, ids, context=context):
# As I understood prj_id it is many2one field. For example I set name of prj_id
res.append((record.id, record.prj_id.name))
return res
If you need use custom name for specific field you can use context
to call your custom method like this:
<!-- in your view.xml -->
<field name="project_id" widget="selection" context="{'compute_name': '_get_my_name'}"/>
Model must looks like this:
class TestProject(osv.Model):
_name = 'test.project.name'
def name_get(self, cr, uid, ids, context=None):
if u'compute_name' in context:
# check value from frontend and call custom method
return getattr(self, context[u'compute_name'])(cr, uid, ids, context)
else:
# call base method
return super(TestProject, self).name_get(cr, uid, ids, context=context)
def _get_my_name(self, cr, uid, ids, context):
res = []
for record in self.browse(cr, uid, ids, context=context):
res.append((record.id, record.prj_id.name))
return res
One more thing about this solution.
This way works fine only when you use widget="selection"
. Otherwise your custom name will use only for items in dropdown, but selected value will use default name.