On 10/02/11 09:04, hank23 wrote:
Is there anyway in a form definition to specify how the options for a
select widget are to be coded when they're be generated automatically?
Specifically is there a way to specify where the value and the
displayed data attributes of the generated options are to pull that
data from when they're formatted? Thanks for the help.


I'm not sure if I exactly understand your question.

Here's a code snippet of mine that dynamically generates form fields for each CustomerQuestion. Is that the kind of thing you're after?


class CustomerForm(forms.Form):
    name = forms.CharField(max_length=128)

    def __init__(self, *args, **kwargs):
        super(CustomerForm, self).__init__(*args, **kwargs)
        for question in CustomerQuestion.objects.all():
            self.fields[question.name] = forms.ChoiceField()
            answers = question.answer_set.all()
            self.fields[question.name].choices = [(ans.id, ans.name)
                                         for ans in answers]


Lex.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to