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:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 2 24
|
2093 | ||
|
0
thg 7 24
|
3143 | ||
|
0
thg 7 22
|
60 | ||
|
1
thg 7 22
|
3049 | ||
|
2
thg 12 23
|
33566 |