Reputation: 95
I am beginner in Odoo and python, and I want to create a simple module, which should insert some categories for a person (student, employee,...), and then insert persons with field category. My question is, how to create p_c_view.xml. I tried to adjust some xmls examples that I found, but had no success. Here is my p_c.py file. Thanks
class p_c_person(osv.osv):
_name = "p_c.person"
_description = "Person"
_columns = {
'name': fields.char('Persone', size=128, required=True),
'categories': fields.one2many('p_c.category', 'category_id', 'Categories'
}
p_c_person()
class p_c_category(osv.osv):
_name = "p_c.category"
_description = "Category"
_columns = {
'name': fields.char('Category', size=128, required=True),
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
}
p_c_category()
Upvotes: 3
Views: 10634
Reputation: 14746
Many2one
Store a relation against a co-model:
Specific options:
Example:
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
One2many
Store a relation against many rows of co-model:
Specific options:
Example:
'categories': fields.one2many('p_c.category', 'property_id', 'Categories'),
Refer Odoo documentation
One2many
field only created for relational many2one
field of that model, it gives you freedom to travelling bi-directional. Odoo engine manage integrity while you create record in reference model in which you have define many2one
field then you will see the effect in one2many
field as well.
Upvotes: 4
Reputation: 11141
one2many field takes responding many2one field with that object.
try with this code
class p_c_person(osv.osv):
_name = "p_c.person"
_description = "Person"
_columns = {
'name': fields.char('Persone', size=128, required=True),
'categories': fields.one2many('p_c.category', 'property_id', 'Categories'
}
p_c_person()
class p_c_category(osv.osv):
_name = "p_c.category"
_description = "Category"
_columns = {
'name': fields.char('Category', size=128, required=True),
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
}
p_c_category()
For more details you may visit odoo documentation.
Upvotes: 4