Is it possible to make one relationship without specifying the target model “foreign key field”?

I want to create a superclass that has a one2many relationship with the message dummy.one . So every subclass that inherits superclass will have one2many relationship with dummy.one . The problem is declaring a one2many relationship forces me to specify a foreign key that binds dummy.one to superclass . Thus, I need to create a many2one relationship (foreign key) in dummy.one for each subclass I subclass .

The only trick that works is that I create a many2many relationship instead of one2many .

Here is an example:

 'dummies' : fields.one2many('dummy.one','foreign_key','Dummies'), 

Many2Many:

 'dummies' : fields.many2many('dummy.one',string='Dummies'), 

Is there a better way to achieve the same effect as many2many without declaring the many2one field in dummy.one for each subclass ?

0
python openerp odoo odoo-8
source share
2 answers

Instead of using Python inheritance, you might prefer to use ORO ORO inheritance, which is delegation inheritance. See the following example:

 class book(models.Model): _name = 'books.book' name = fields.Char() author = fields.Many2one('books.author') class author(models.Model): _name = 'books.author' name = fields.Char() books = fields.One2many('books.book', 'author') class better_author(models.Model): _name = 'books.author' _inherit = 'books.author' curriculum = fields.Text() 
+2
source share

Try creating a many2one relationship (foreign key) in dummy.one for a superclass, not for every subclass.

+1
source share

All Articles