1 from django import forms
2 from django.forms.widgets import RadioSelect
3 from django.utils.translation import ugettext_lazy as _
4 from quiz.models import Answer
6 class QuestionForm(forms.Form):
7 answer = forms.ModelChoiceField(widget=RadioSelect,
8 queryset=Answer.objects.all(), empty_label=None,
9 error_messages={'required': _('Please select an option')})
11 def __init__(self, instance, *args, **kwargs):
12 r = super(QuestionForm, self).__init__(*args, **kwargs)
13 self.fields['answer'].queryset = instance.answer_set.all()