Odoo Help

0

Model with many2many relation to his self

By
Michael Berg
on 6/25/15, 4:09 AM 801 views

Hello

I want to create a model Category who can has many SubCategories and can be a SubCategory of more than one Category.

How I am able to do this in Odoo v8.0


This is the way I would do it. But there raise an error that i'm not able to create a relation to the same model.

class ebay_categories(models.Model):

_name = "famberg.categories"

_rec_name = 'CategoryName'

_sql_constraints = {('unique_CategoryID', 'unique(CategoryID)', 'The CategoryID needs to be unique!')}


CategoryID = fields.Char(size=10, string="Ebay Category ID")

CategoryName = fields.Char(size=30, string="Ebay Category Name")

CategoryParentIDs = fields.many2many(comodel_name="famberg..categories",inverse_name="Category", string="Parrent Categorys")

0

Bole

--Bole--
2395
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 6/29/15, 8:20 AM

When creating m2m relation, both related models must have a m2m field... in your case, it is one model, but is still need to have BOTH m2m fields... 
so i guess you should define :

CategoryParentIDs = fields.Many2many(comodel_name='famberg.categories'...
CategoryChildIDs = fields.Many2many(comodel_name='famberg.categories'...

in order to have proper many2many relation on the same model


hope it helps

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/25/15, 4:09 AM
Seen: 801 times
Last updated: 6/29/15, 8:20 AM