python - make ChoiceField() take any value -
i'm using forms framework , i'm using of javascript magic inject values on fly select box (the values of select box relies on value form another).
basically have team , players. need define player, players data comes team.
in form class have
team = forms.modelchoicefield(queryset=team.objects.all() player = forms.choicefield()
in front end when user selects team select box, (empty) players boxes gets correctly updated new data. when hit submit, player select box throws error select valid choice. 2 not 1 of available choices.
2 valid choice however.
is there way around this? can make choicefield() take value?
ordered complexity desc:
- prepopulate possible choices. example, if select player's id,
choices = player.objects.values_list('id', flat=true)
- define
charfield
, render manually in template select box. - don't define in form, pass it's value form's constructor (which need override process value.)
Comments
Post a Comment