Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4740 Представления

I'm following the v14 tutorial where the goal is to populate fields when a checkbox is set, and remove said populated fields if its unset. 

Specifically: 

Set values for garden area and orientation.

Create an onchange in the estate.property model in order to set values for the garden area (10) and orientation (North) when garden is set to True. When unset, clear the fields.


It the field were a string it would be as easy as  self.name = "someName", but in a selection field, I am guessing it is not as easy.


I have      

    garden = fields.Boolean()

garden_orientation = fields.Selection(string="Direction", selection=[('West', 'west'), ('North', 'north'), ('South', 'south'), ('East', 'east')]    )


And also further down:

    @api.onchange("garden")   

 def _onchange_garden(self):        

self.garden_orientation = "north" #??? 


 The examples given don't show a selection field being set, so I'm at a bit of a loss. 

Аватар
Отменить
Лучший ответ

Try the below:

garden = fields.Boolean()
garden_orientation = fields.Selection(string="Direction", selection=[('west', 'West'), ('north', 'North'), ('south', 'South'), ('east', 'East')])

@api.onchange("garden")
def _onchange_garden(self):
    # if the garden = True
    if self.garden:
        self.garden_orientation = "north"
    else:
        self.garden_orientation = False
Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
окт. 21
4181
2
дек. 24
1183
1
авг. 23
2519
0
сент. 21
2083
16
мар. 24
29618