跳至內容
選單
此問題已被標幟
4 回覆
3867 瀏覽次數

Hello i make selection field 

registered_by_police = fields.Selection(selection=BOOLEAN_SELECTOR, string='Registered by')
BOOLEAN_SELECTOR = (
(False, _('No')),
(True, _('Yes')),
)

and call in view

<field name="registered_by_police" widget="radio" string="Registered by Police?"/>

if i choose no all is ok, it show no in view and i am happy. But when i choose Yes it show free space and don't save my choose. How can i solve this problem. and maybe i can make boolean field and make similar display

 
頭像
捨棄
作者

I need to use boolean values ​​because before this field was boolean and now the client wanted a different type of visual and I tried to make the old records work too, maybe there are some other solutions to the problem

最佳答案

This is because you have not declared selection properly. It needs to be key and value.

Replace your selection code with the following syntax:

BOOLEAN_SELECTOR = (

('False', _('No')),

('True', _('Yes')),

)

Hope it helps you!

Thanks,

Mayank

頭像
捨棄
作者

I need to use boolean values ​​because before this field was boolean and now the client wanted a different type of visual and I tried to make the old records work too, maybe there are some other solutions to the problem

If you need boolean value then use the above syntax of key, value and you can try any of two methods:

1 - On write method you can check if selection field value is 'Yes' then your boolean should be True else False. You need to add a boolean field before that.

2 - Add a boolean field and add onchange method for it. On onchange if your selection Field has value is 'Yes' then your boolean should be True else False.

This additional step will allow you to manage within your existing workflow.

Note: Boolean field should be the original field that your system needs to have as boolean and this selection field will be a field for reference through which you can set your boolean field.

Thanks,

Mayank

作者

Thanks for help. but i wrote widget for boolean field and solve my problem

最佳答案

Check how you can make selection field

selection_field=fields.Selection([('True','Yes'),('False','No')],'Registered By Police')


頭像
捨棄
作者

i need to use boolean types not sring in my database