Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
13513 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

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

Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mei 22
4336
1
aug. 19
4254
1
dec. 21
6675
0
okt. 21
3302
1
okt. 21
4126