Edit the models/library_book.py file to add the new related field:
- First, we need to add a helper method to dynamically build a list of selectable target models:
from odoo import models, fields, api class LibraryBook(models.Model): # ... @api.model
def _referencable_models(self):
models = self.env['ir.model'].search([
('field_id.name', '=', 'message_ids')])
return [(x.model, x.name) for x in models]
- Then, we need to add the Reference field and use the previous function to provide a list of selectable models:
ref_doc_id = fields.Reference( selection='_referencable_models', string='Reference Document')
Since we are changing the model's structure, a module upgrade is needed to activate these changes.