İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
13481 Görünümler

According to the documentation, it is possible to assign the result of a function as default value of a field. But is it possible to assign the value of another field of the same model as default value?

Example:

display_name = fields.Char(string='Display Name', default=name, translate=True)
Avatar
Vazgeç
En İyi Yanıt

Hi,

you can use

@api.onchange('<field whose value to be taken>')

def onchange_func(self):

if self.<field value to be taken>:

self.  <field to which you need value> = self.<field  whose value to be taken>

Avatar
Vazgeç
Üretici

Thanks for your reply. How would my field definition look like then:

display_name = fields.Char(default=onchange_func(name)) ?

En İyi Yanıt

You can achieve that by this one-liner, note though that the value of the other field should be created afore:


display_name = fields.Char(string='Display Name', default=lambda self: self.name, translate=True)

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
May 22
4293
1
Ağu 19
4217
1
Ara 21
6646
0
Eki 21
3283
1
Eki 21
4099