April 2019
Beginner to intermediate
774 pages
24h 59m
English
For this recipe, we will use the following model definition:
class LibraryBook(models.Model):
_name = 'library.book'
name = fields.Char('Title')
isbn = fields.Char('ISBN')
author_ids = fields.Many2many('res.partner', 'Authors')
@api.multi
def name_get(self):
result = []
for book in self:
authors = book.author_ids.mapped('name')
name = '%s (%s)' % (book.name, ', '.join(authors))
result.append((book.id, name))
return result
When using this model, a book in a Many2one widget is displayed as Book Title (Author1, Author2...). Users expect to be able to type in an author's name and find the list filtered according to this name, but this will not work since the default implementation of name_search only uses the attribute referred ...
Read now
Unlock full access