Scratch that. I ended up doing it the other way. I went back and reviewed and it seemed less ugly now than it did at midnight last night. Funny, that. Thanks for the advice.
On Apr 10, 10:45 am, Laereom <jamesdbo...@gmail.com> wrote: > Honestly, I really don't like that method, mostly due to ugliness. > I'm looking for a solution specifically to instantiating a form > created via a class factory, unless that is some sort of Herculean > task. > > On Apr 10, 10:13 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > > > > > On Apr 10, 4:40 pm, Laereom <jamesdbo...@gmail.com> wrote: > > > > As the title suggests, I'm creating a dynamic form via a class > > > factory. > > > > Here is what I'm doing inside the class factory itself (as far as > > > actually making the class goes): > > > class _QuestionAnswerForm(forms.Form): > > > response = > > > forms.IntegerField(widget=RadioSelect(choices=choice_list)) > > > return _QuestionAnswerForm > > > > Here is what I'm doing outside the class factory: > > > > _QuestionAnswerForm = > > > question_manager.generate_question_form(1,question) > > > question_answer_form = _QuestionAnswerForm() > > > > I'm a bit ambiguous on the details of how class factories / etc work, > > > so I may be doing that bit wrong. > > > > Either way, when I try to render this as either just a string or a > > > form, I get the following error:t > > > > Caught an exception while rendering: string index out of range > > > > Peeking at the local variables, question_answer_form appears to be: > > > <agora.questionmanager._QuestionAnswerForm object at 0x90d69ac> > > > > Note that it is an object rather than an instance. I suspect that's > > > my problem, due to some quirk of dynamic classes, but I have no idea > > > how to fix it. > > > > Any advice? > > > Is the only reason you're doing a classfactory in order to set the > > choices dynamically? If so, a much easier way is to use a normal > > class but override the __init__ method and set the value of > > self['fieldname'].choices there. > > > -- > > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.