Create many2one and one2many relationship in OpenERP
In OpenERP we can create many2one and one2many relationships between models very easily by creating many2one and one2many fields. You just need to declare a field in _columns and then using this field normally in the rest programming and views as we normally do.
I created a small module to explain called hospital, I have two objects patient and doctor. To establish relationship between these two entities or objects, create doctor_id field in patient model as many2one, and patient_id as one2many in doctor model.
The relationship can be explained as one doctor with many patients and many patients going to a single doctor.
Now create a many2one field as:
in class patient(osv.osv):
- 'doctor_id':fields.many2one('doctor','Doctor'),
- 'patient_id':fields.one2many('patient','doctor_id',),
- fields.many2one(
- 'object.name',
- 'field name',
- optional parameters)
declaring a one2many field:
To view the full blog about Create many2one and one2many relationship in OpenERP please visit Findnerd.