def __init__(self, question_set, *args, **kwargs):
        """
        Create a form object from a question set.
        Method takes and option related_object keyword argument that relates
        the survey to an instance of a Django model.
        """
        
        # get related_object and remove from kwargs that are passed to super.__init__
        related_object = kwargs.get('related_object', None)
        try:
            del kwargs['related_object']
        except KeyError:
            pass
        
        # pull possible answer_set parameter from kwargs
        answer_set = kwargs.get('answer_set', None)
        try:
            del kwargs['answer_set']
        except KeyError:
            pass
        
        # call super constructor to setup initial fields of form
        super(self.__class__, self).__init__(*args, **kwargs)
        
        # iterate over questions and create corresponding form fields
        for question in question_set.questions.order_by('order'):
            
            name = "answer_for_%i" % question.id
            field = self._get_field(question)

            if field:
                self.fields[name] = field
                
        # add related object if one was specified
        if related_object:
            ct = ContentType.objects.get_for_model(related_object)
            related = u"%i:%s" % (ct.id, related_object.pk)
            self.fields['related'] = forms.CharField(widget=forms.HiddenInput, initial=related)
            if answer_set:
                self.data['related'] = related
        
        # populate form with answer_set data if it exists
        if answer_set:
            self.fields['answer_set'] = forms.CharField(widget=forms.HiddenInput, initial=answer_set.pk)
            self.data['answer_set'] = answer_set.pk
            self.is_bound = True
            for question, answer in answer_set.q_and_a():
                name = "answer_for_%i" % question.id
                self.data[name] = answer.text
                
        # add question set
        self.fields['question_set'] = forms.CharField(widget=forms.HiddenInput, initial=question_set.slug)
        if answer_set:
            self.data['question_set'] = question_set.slug
dataset/ETHPy150Open sunlightlabs/django-simplesurvey/simplesurvey/forms.py/SurveyForm.__init__/original