Hello Djangonauts, After spending sometimes to learn using the test/fail/correct cycle I have finally reach a point where I have something that more or less do what I want. However since one of the objectives of the project I am working on was to improve my knowledge on django I would like to read from you how to improve what I have done.
The goal is to generate dynamically a form using the newforms library. This forms should all the user to create an Interview (models.py:http://dpaste.com/hold/14560/ ) What I have done so far is create this custom form: class AnswerPollForm(forms.Form): def __init__(self, poll_id, *args, **kwargs): super(AnswerPollForm, self).__init__(*args, **kwargs) self.poll = Poll.objects.get(id=poll_id) for c in self.poll.choice_set.iterator(): self.fields[c.id] = forms.BooleanField(label=c.choice,required=False) That I use in this view (http://dpaste.com/hold/14562/). The interesting part is that I create a list of tuple made with the polls and the forms representing them. This allow me to create a single form that I can use to collect the interview to a survey. list_answer_forms =[] for poll in survey.poll_set.iterator(): list_answer_forms.append((poll,AnswerPollForm(poll.id))) [...] return render_to_response('dj_survey/template/ add_interview_forms.html', {'list_answer_forms': list_answer_forms, 'survey': survey, 'request': request}) This list of forms is then used in the following template: <h1>Welcome to {{ survey.name }}</h1> <p>{{ survey.description }}</p> <br></br> <FORM action="." method="post"> {% for poll,form in list_answer_forms %} <h2>{{ poll.title }} | {{ poll.question }}</h2> <FIELDSET> {{ form.as_ul }} </FIELDSET> {% endfor %} <INPUT type="submit" value="Submit"> <INPUT type="reset"> </FORM> This is not bat but i would prefer if instead of the list of tuple containing my forms could directly instantiate a "all in one" form. This would avoid the loop on list_answer_forms. This is were I get stuck. Could you please let me know how to add html text between the field? like "<h2>{{ poll.title }} | {{ poll.question }}</h2>" Any other improvement is more than welcome. Thank you for your time. Regards, --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

