Re: How to put some data from view the form
Many thanks Daniel's advice solve the problem. I also try call initial value, form = MyForm(initial={'someArg': 'value',}) It look better, to send data without create __init__ but this doesn't work to me. And this working well: def __init__(self, someArg, *args, **kwargs): self.someArg=someArg super(MyForm, self).__init__(*args, **kwargs) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How to put some data from view the form
On Feb 22, 10:14 am, Mintaka <[EMAIL PROTECTED]> wrote: > Hi > > I would like to put some data from view to form when I create it. > Standard way is to use __init__ metod, but after using __init__ in > form class, > form stop working. > > Pleas what I'am doing wrong? > > Fragments of example > > - view - > def MyView(request): > form = MyForm("value") > return render_to_response('MyTemplate.html', {'form': form}) > > - form - > class MyForm(forms.Form): >item = forms.BooleanField() > >def __init__(self, someArg): > self.someArg=someArg > > - template - > > MyTemplate > > > {{ form.as_table }} > > > > > - Result in page (show source in browser)-- > MyTemplate > > > > > > If you're going to override __init__, make sure you call the parent object's version with super: def __init__(self, someArg, *args, **kwargs): self.someArg=someArg super(MyForm, self).__init__(*args, **kwargs) -- 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-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 -~--~~~~--~~--~--~---
Re: How to put some data from view the form
Hi, Don't implement __init__ yourself, you can pass initial data to the form like this : form = MyForm(initial={'someArg': 'value',}) Hope that helps, Mike On 22 Feb 2008, at 10:14, Mintaka wrote: > > Hi > > I would like to put some data from view to form when I create it. > Standard way is to use __init__ metod, but after using __init__ in > form class, > form stop working. > > Pleas what I'am doing wrong? > > > Fragments of example > > - view - > def MyView(request): >form = MyForm("value") >return render_to_response('MyTemplate.html', {'form': form}) > > > - form - > class MyForm(forms.Form): > item = forms.BooleanField() > > def __init__(self, someArg): >self.someArg=someArg > > > - template - > > MyTemplate > > >{{ form.as_table }} > > > > > > - Result in page (show source in browser)-- > MyTemplate > > > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to put some data from view the form
Hi I would like to put some data from view to form when I create it. Standard way is to use __init__ metod, but after using __init__ in form class, form stop working. Pleas what I'am doing wrong? Fragments of example - view - def MyView(request): form = MyForm("value") return render_to_response('MyTemplate.html', {'form': form}) - form - class MyForm(forms.Form): item = forms.BooleanField() def __init__(self, someArg): self.someArg=someArg - template - MyTemplate {{ form.as_table }} - Result in page (show source in browser)-- MyTemplate --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---