python - Odoo model relationship -
i know how make header->detail
relationship using one2many
relationship. pretty simple, in real world need have more complicated things that.
in case have these tables.
student homework paper test -------------------------------------------- id id id id name subject title score
the student
table has
one2many
homework
one2many
paper
one2many
test
and also
homework
hasmany2one
student
paper
hasmany2one
student
test
hasmany2one
student
resulting in these relationships
student homework paper test -------------------------------------------- id id id id name subject title score homework_ids student_id student_id student_id paper_ids test_ids
i make form student
model , input homework
, paper
, , test
form using one2many
widget.
but if wanted have form homework
model choose student
first , input homework
, form i'd see(or input) other information such paper
, , test
?
using many2many
relation between homework
, paper
, , test
have student's paper
, , test
accessible homework
seems weird me. complicates database structure, creating unnecessary many2many
relation.
is there way instead of using many2many
relation? feel database structure ugly if used that.
this huge concern me looking @ odoo heavily model dependent framework. must start right model first!
when have many2one field can create related field show them in current form.
your case in homework model can create related field one2many field of paper.
paper_ids = fields.one2many(related='student_id.paper_ids', readonly = true)
i'm assuming field named paper_ids when create related field keep same type in case one2many field , can remove readonly if want user able edit field form. related field compute field not stored in database if want store in database must set store = true.
hope helps you
Comments
Post a Comment