class PollForm(forms.Form): answer = forms.ChoiceField( widget=forms.RadioSelect, choices=cool_choices)
def __init__(self, poll, *args, **kwargs): super(PollForm, self).__init__(*args, **kwargs) b = poll.choice_set.all() list_choice = [] for i in range(len(b)): list_choice.append(b[i].choice) list_choice = zip(list_choice, list_choice) self.fields['answer'].choices = list_choice self.fields['answer'].label = poll.question self.fields[poll.pk] = self.fields['answer'] del self.fields['answer'] So I managed to fix it by creating a name tag for each of the radioselect options. I thought self.fields['answers'].widget.name would let me set the tag but that did not work as there was no default name tag. So I googled and I found that the last two lines made it work self.fields[poll.pk] = self.fields['answer'] del self.fields['answer'] It set the name tag as the pk for the poll. I honestly don't understand how that works. Could you please explain how the last two lines work? On Saturday, October 21, 2017 at 6:41:16 PM UTC-4, James Schneider wrote: > > > > > Since each form is set to only allow you to select 1 multiple choice > option, if I add many forms in one page, I can only select one option > overall. So if I answer question 1, I can't answer any of the other > questions without it unselecting question 1's answer. > > Does anyone know how to fix this? > > > If that's the case you are not formatting the form correctly. Each form > set should contain it's own radio group of answers so that an answer may be > selected for each one. Post up the template code you're using. > > -James > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e873025d-aee6-4793-9907-ee8dd3f5bca1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.