Skip to Content
Menu
This question has been flagged
2 Replies
744 Views

Hi,

I currently have a model which has relational fields connected with other models, but I want them to become static when the object is created.

Is there a way to have static fields, but the form showing the other model's data ? I mean when I create the object, I want :

1) to be able to choose an object from the other model to associate,

2) but when saved, the "relational" fields become static, so changing data in the other model doesn't update data in this one


I hope I have been clear,

Thanks,

Hugo

Avatar
Discard
Best Answer

Hi,

To me, you are describing a computed field.

You'll need two fields : one Many2One to link the other model, and one that will be the static one (then an Integer, a Text, a Float, or whatever you want)

randomm2o = fields.Many2one(comodel_id='model.name')

staticfield = fields.Text(compute='_compute_staticfield')


@api.onchange('randomm2o') def _compute_staticfield(self):     for record in self:         record.staticfield = record.randomm2o.wantedfield
Avatar
Discard
Author Best Answer

Hi,

Thanks for the answer, I think it's close to what I exactly want...

Is it possible the make the static field "unlinked" to the relationnal ? So when I change the related model's fields, it doesn't update the static field ?


Avatar
Discard