Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
13518 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

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

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
kvě 22
4339
1
srp 19
4256
1
pro 21
6676
0
říj 21
3303
1
říj 21
4126