edbo
1
A Reference field basically consists of two fields:
- Selection field, so the user can select a model
- Many2One field, so the user can select a record from the selected model
The question is now: How do I programmatically get the list of models which is needed for the Selection field? What RPC command can I use for that?
ced
(Cédric Krier)
2
It is defined in the field definition by the attribute selection
.
When the selection
refers to a method, the method is available for RPC.
edbo
3
Hmm, when I get the field definition by
model.calendar.item.fields_get(["origin"])
I get an object back with all the parameters. Also I see
{
....
selection: "get_origin"
sort: true
sortable: true
....
}
So I did a model.calendar.item.get_origin
and surprisingly I got an array back with the models! I dug a bit deeper into my code and indeed:
origin = fields.Reference('Origin', selection='get_origin')
@classmethod
def get_origin(cls):
Model = Pool().get('ir.model')
models = cls._get_origin()
models = Model.search([
('model', 'in', models),
])
return [('', '')] + [(m.model, m.name) for m in models]
Tryton is such a nice piece of software
1 Like
system
(system)
Closed
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.