This question has been flagged
2 Replies
4506 Views

Hello guys,

I have to update a field'values in model.

sex = fields.Selection([('male','Male')], string='Sex')


How to put a new data into the selection field ?

sex.append(('female','Female')) doesn't work and it tell me 

TypeError: list indices must be integers or slices, not str


Thanks

Avatar
Discard
Author

/!\ I have two lists

from collection import Counter


fruits = ['Apple','Banana','Orange','Ananas']

begin_with_a = ['Apple','Ananas'] # denied list

fruits = list(Counter(fruits) - Counter(begin_with_a)).elements() # result [ 'Banana','Orange']

info default_get function, the fields.Selection 

fields['fruits'] = [(f.lower(),f) for f in fruits]

Best Answer

Review the selection_add option of class odoo.fields.Selection

https://www.odoo.com/documentation/13.0/reference/orm.html#advanced-fields 

selection = [('a', 'A'), ('b', 'B')]
selection_add = [('c', 'C'), ('b',)]
> result = [('a', 'A'), ('c', 'C'), ('b', 'B')]


Avatar
Discard