Hi there,
I am trying to use a reference field to allow any model selection. I have the following models
class eaxpl_workflow(models.Model):
_name = 'eaxpl.workflow'
document_model_id = fields.Many2one('ir.model')
class eaxpl_workflow_instance(models.Model):
_name = 'eaxpl.workflow_instance'
workflow_id = fields.Many2one('eaxpl.workflow', string="Workflow", required=True)
document_model_id = fields.Many2one('ir.model', related='workflow_id.document_model_id')
document_reference = fields.Reference(
selection=??????
)
The question is what to put in selection attribute of the reference field to limit the model selection to the model which is populated in the document_model_id field?
I have found the following snippet, but it has no context of the current model.
@api.model
def _reference_models(self):
models = self.env['ir.model'].sudo().search(
[('state', '!=', 'manual')])
return [(model.model, model.name)
for model in models
if not model.model.startswith('ir.')]
Is it even possible? How would you approach such a problem?