Thanks Jeff. I also realized there is a provision to pass nested tuple like choices to form while initalizing using field_list (Not documented but found in django testing documents)
http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/forms.py (lines 715 - 797 ) Thanks, Srikanth On Jul 16, 1:55 pm, Jeff FW <[EMAIL PROTECTED]> wrote: > In __init__, where you call form.Form's __init__, you need to pass > data, *not* None. Also, you shouldn't try to duplicate all of the > arguments. This should work better: > > def __init__(self, cat_slug, data=None, *args, **kwargs): > forms.Form.__init__(self, data=data, *args, **kwargs) > > Also, I'm not sure if you modified your view, but you have to pass > request.POST when you instantiate the form in order for that to > actually work. > > -Jeff > > On Jul 16, 6:01 am, Srik <[EMAIL PROTECTED]> wrote: > > > Hi Jeff, > > > I did try to move __init__ but the problem still exists. > > > I tried to keep title and email along with other fields so that they > > will be appear in same order in Form. > > > class MyForm(forms.Form): > > > def __init__(self, cat_slug, data=None, files=None, auto_id='id_%s', > > prefix=None, initial=None, error_class=ErrorList, label_suffix=':'): > > forms.Form.__init__(self,data=None, files=None, > > auto_id='id_%s', > > prefix=None, initial=None, error_class=ErrorList, label_suffix=':') # > > Took those extra fileds from BaseForm class. > > cat = Category.objects.get(slug=cat_slug) > > self.fields['title'] = forms.CharField(max_length=50) > > self.fields['email'] = forms.EmailField() > > if cat.attributes.all(): > > for i in cat.attributes.all(): > > self.fields[i.name] = > > forms.CharField(label=i.name) > > > Regards, > > Srikanth > > > On Jul 15, 7:14 pm, Jeff FW <[EMAIL PROTECTED]> wrote: > > > > You have to pass the data into the form when instantiating it, eg: > > > form = MyForm(request.POST) > > > > However, that means (for your example), the fields wouldn't exist yet-- > > > move them into __init__ instead. > > > > Some other things to note: you don't need to "title" and "email" to > > > the form dynamically--might as well put them in the MyForm class > > > definition. Unless you're planning to upload files, you don't need > > > the enctype attribute in the form tag. > > > > -Jeff > > > > On Jul 15, 9:54 am, Srik <[EMAIL PROTECTED]> wrote: > > > > > Hi Djangoers, > > > > > I'm trying to generate a form dynamically using MyForm (Form class), > > > > but I'm stuck with validating or populating data. > > > > > Form Class, View and template Code here:http://dpaste.com/65080/(not > > > > too many lines I guess :) ) > > > > > Good thing is I can see form (generating dynamically, based on the > > > > category I chose as expected), but I'm not able to do anything after > > > > that . > > > > > When I submit form with empty values, its returning empty form no > > > > matter I enter data or not and also it won't throw any errors(like > > > > field required) > > > > > Thanks, > > > > Srikanth --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---