django-select-multiple-field icon indicating copy to clipboard operation
django-select-multiple-field copied to clipboard

int values are converted to strings

Open Hinnack opened this issue 9 years ago • 3 comments

if I have the following choices:

MY_CHOICES = ( (0, _('val1)), (1, _('val2')), )

I get an array ["0", "1"]

Hinnack avatar Oct 04 '15 19:10 Hinnack

This is a limitation of the field. It requires strings. I'll change the docs to make it explicit.

kelvinwong-ca avatar Oct 18 '15 08:10 kelvinwong-ca

If you needed to have integer choices you would probably have to subclass the field. I don't see a way to detect a difference between u'1' and 1 once it is stored. The storage of choices is delegated to a CharField. For example, in the db you have:

choices: '1,2,3,4'

Does that mean you should return to the user: [1,2,3,4] or ['1','2','3','4']? You cannot tell based on the values in the field.

kelvinwong-ca avatar Oct 18 '15 23:10 kelvinwong-ca

but you could tell based on the choices... But it is alright! I did not realize, that it is a subclassed select widget.

Henner avatar Oct 19 '15 10:10 Henner