I was reading and poking around, and I found this: http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields I believe it explains how to accomplish what you want to do.
Cheers! Jeff Anderson Jeff Anderson wrote: > Actually, I just got an idea for a simple website, and it would need the > same thing accomplished. I haven't had any time to look into it yet, but > I know that python has the ability to generate classes and methods on > the fly. I have never used it, but I am guessing it will be possible to > create form instances on the fly. > Storing their results would be a bit ugly, unless you wanted to create > new tables for each time a user creates a new form. The way I can think > to do it would be to pickle the form instance, and unpickle it again. > Pickling is another python feature that I haven't looked into yet > either. Hopefully that is the correct direction to head to accomplish this. > > Cheers! > > Jeff Anderson > > Vincent Woon wrote: > >> Hi, >> >> I'm new to Django and Python and I would appreciate if anyone could >> help me out here. I'm trying to create a form-builder program, where >> users can select the form fields they want (such as textbox, string, >> or datefield etc) to create a master form which they can send out to >> others and track their response. >> >> What I want to achieve is this (Please advise me if there's a better >> method). I want to create a <userform> model, and fields that the user >> creates are passed in as a dictionary similar to the newforms library >> documentation ( http://www.djangoproject.com/documentation/newforms/) >> which wrote something similar to: >> >> data = {'subject': 'hello', >> 'message': 'Hi there', >> 'sender': '[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>', >> 'cc_myself': True} >> f = ContactForm(data) >> >> The main problem I have is that I am not sure what values to use for >> the dictionary keys when defining my <userform> class. I tried passing >> in an empty class as below, in the hope that I can pass to it, a >> dictionary containing the values and keys a user designed. >> >> class Userform (forms.Form): >> pass >> >> When I tried to run the command (python manage.py syncdb), the table >> cannot be created. The SQL command are just >> >> Begin; >> Commit; >> >> >> How can I design my userform model? The examples and tutorials I've >> read through so far only mentioned cases where the attributes of the >> tables we create are known. For example, >> >> class Choice(models.Model): >> poll = models.ForeignKey(Poll) >> choice = models.CharField(max_length=200) >> votes = models.IntegerField() >> >> The choice of attributes are clear cut in this example because it is >> up to the developer to decide the required table attributes. However >> in my case, the attributes of the table are set by the user and I have >> no idea what his/her attributes are. >> >> I would appreciate any advice or feedback on this, and any readings >> which you think would be helpful. :) >> >> Regards, >> Vincent Woon >> >> --~--~---------~--~----~------------~-------~--~----~ >> 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 >> [EMAIL PROTECTED] >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en >> -~----------~----~----~----~------~----~------~--~--- >> > >
signature.asc
Description: OpenPGP digital signature