You can do something like this (untested):
class Survey(models.Model):
question = models.CharField(maxlength=100)
class SurveyForm(forms.form):
def __init__(self, *args, **kwargs):
super(SurveyForm, self).__init__(*args, **kwargs)
for o in Survey.objects.all():
self.fields['question_%s' % o.id] = forms.CharField()
Now you will have a question field in your form corresponding
to each row in Survey, i.e. question_1, question_2, etc. You
will need to override the save() method in SurveyForm to read
through the fields and save the responses somewhere -- not in
Survey.
--
Jeff Bauer
Rubicon, Inc.
On Jan 23, 7:07 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I have a model similar to the quickstart tutorial for a survey. One
> object consists of questions. I would like to generate a form based on
> the data in this table, for instance, a field object for each row in
> the database. Is there some way to do this with newforms? I'm afraid
> I don't have enough Python experience to know if I can make a "dynamic"
> form class like that.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---