How to do it...

Edit the models/library_book.py file to add the new related field:

  1. 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]
  1. 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset