Odoo Help

Welcome!

This community 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.

0

Model with many2many relation to his self

By
Michael Berg
on 6/25/15, 4:09 AM 641 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--
2385
| 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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