python - Coerce in django forms -


what coerce argument in django forms? i've read documentation, not helpful, explanation few examples of use cases helpful. quote documentation:

a function takes 1 argument , returns coerced value. examples include built-in int, float, bool , other types. defaults identity function.

typedchoicefield choicefield, except choicefield return unicode.

with typedchoicefield pass function takes 1 argument , returns value cast type want. example, if want coerce value integer, use:

int_field = forms.typedchoicefield(choices=some_choices, coerce=int) 

the field value integer or fail validation.


Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -