Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
912 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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
Imagine profil
Abandonează
Autor Cel mai bun răspuns

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 ?


Imagine profil
Abandonează