Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3775 Weergaven

I want to add a select list to the Product Template view which shows values from my new, supplemental table.  I found this function in the documentation:

Using relation fields many2one with selection. In fields definitions add:

..., 'my_field': fields.many2one( 'mymodule.relation.model', 'Title', selection=_sel_func), ...,

And then define the _sel_func like this (but before the fields definitions):

def _sel_func(self, cr, uid, context=None):
obj = self.pool.get('mymodule.relation.model')
ids = obj.search(cr, uid, [])
res = obj.read(cr, uid, ids, ['name', 'id'], context)
res = [(r['id'], r['name']) for r in res]
return res

This works, and I correctly get the name field in the selection list, and the database stores the record id.  However, I would like to tweak this function a bit, so that I get a concatenation of 'name' and 'description' in my selection list.  I have tried various options, but my selection list always renders exactly the same as before.  I know very little Python.  How would I modify the above function to get '[name] description' as the displayed option in my select list?

Avatar
Annuleer
Beste antwoord

Write a "name_get" method in your object " mymodule.relation.model", and by using a context (which helps ypu decide how to frame the name value), then you can display a concatenated data...

And coming to this object, in XML pass a context on the field "my_field", which will be carried to the name_get of the its model

Avatar
Annuleer
Auteur

Um... like I said, I know very little Python. Could you provide a more concrete example? I don't have much of a grasp on contexts. If I understand what you're saying about the "name_get" method (is that an API method?) it should be defined in the class from which I want to retrieve data, and would return the name + description concatenation as "name"?

Gerelateerde posts Antwoorden Weergaven Activiteit
9
apr. 22
29036
7
nov. 20
47490
0
mei 20
6279
2
dec. 17
16842
1
jun. 16
11332