Hello, if any one can help me. Usually when you use a many2many relation between two classes Odoo automatically create a many-to-many table.
I want to make my own customized many2many class resultant of a many2many relation between two classes, that many2many class/table must have others fields.
I want to populate and retrieve data from that many2many class/table and fields.
I'm aware that i can make a class, and in consecuence a table with two one2many relation to other tables, and from one of that other table make a many2many relation descraibing the same name of the many2many table.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Hi,
The syntax for Many2Many fields is :-
fields.Many2many(comodel_name=None, relation=None, column1=None, column2=None, string=None)
Here comodel_name is the name of target model,
and relation is name of table that store relation in database. ie it will create a table in database with the given name, which store the relation,
column1 and column2 are the name of columns of relation-table in database.
If you are talking about to and fro relation between two objects(tables). Lets assume that our objects are teachers and subjects, and we want a to and fro relation, i.e. we can add teachers to subject from subject-form-view and we can also add subjects to teacher from teacher-form-view, either way it have to reflect in both sides. This we can achieve using same relation-table for both Many2many fields. For more understanding, refer code
class Teacher(models.Model):
_name = "teacher.teacher"
name = fields.Char(string='Teacher Name')
subject_ids = fields.Many2many('subject.subject', 'teacher_sub_rel', 'subject_id', 'teacher_id', string='Teachers')
class Subject(models.Model):
_name = "subject.subject"
name = fields.Char(string='Subject Name')
teacher_ids = fields.Many2many('teacher.teacher', 'teacher_sub_rel', 'teacher_id', 'subject_id', string='Subject')
Hope this helps.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
1
ก.พ. 24
|
2131 | ||
|
0
ก.ค. 24
|
3172 | ||
|
0
ก.ค. 22
|
60 | ||
|
1
ก.ค. 22
|
3076 | ||
|
2
ธ.ค. 23
|
33614 |