I have a problem with django and forms.
In forms.py I have sth like this:
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
self.answers = kwargs.pop('answers')
super(AnswersForm, self).__init__(*args, **kwargs)
choices = ["aaaa", "ssssssssss", "ddddddddd"]
self.fields['answers'] = forms.ChoiceField(choices = choices, widget=forms.RadioSelect())
And when i use it in template, I have sth like this:
Answers:
- a
- s
- d
Do you know why I haven’t got all words, but only one letter of the word?
choicesshould be a list (or other iterable) of two-tuples. The first entry in each tuple is the value that gets stored in the database. The second is the human-readable name.See the documentation on
choicesfor more information.Thus, your
choiceslist should look more like this:As posted, your code is considering each string (aaaa, ssssssss, etc.) to be tuple-like and grabbing the first letter of each for the database representation, and the second letter of each for the human-readable name (used for the label).