Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7531 Lượt xem

Hello, I am creating a module with a selection field. I would like a float number to be saved to the DB when a user selects a choice from the selection drop down, but when I make a selection then I get an error like this:

DataError: invalid input syntax for integer: "0.25"

So my question is, can floating numbers be used as values for a selection field, or can you use only integers or strings? Thank you

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Yes Selection Field value save characters or Integer in Database.

Format of the selection parameter: tuple of tuples of strings of the form: (('key_or_value', 'string_to_display'), ... )

The below code shows display float value as string in Front view and Back-end store key value.

 'type': fields.selection([('CodeA', '0.25'), ('CodeB', '0.50')], 'Type'),
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 17
16955
0
thg 4 15
3982
1
thg 3 15
9530
1
thg 12 24
1615
1
thg 3 24
1641