December 2018
Beginner to intermediate
404 pages
10h 14m
English
Regular relational fields reference one fixed co-model. The Reference field type does not have this limitation and supports flexible relationships, so that the same field is not restricted to always be pointing to the same destination model.
As an example, we will use it in our book category model to add a reference to a highlighted book or author. So, the field could refer to either a book or a partner:
# class BookCategory(models.Model):
highlighted_id = fields.Reference(
[('library.book', 'Book'), ('res.partner', 'Author')],
'Category Highlight', )
The field definition is similar to a selection field, but here the selection list holds the models available to be used on the field. In the user ...
Read now
Unlock full access