"Initial" parameter can be a callable object. So you can create "lazy getter" for your initial data
On 6 янв, 19:27, shabda <[EMAIL PROTECTED]> wrote: > But I need the initial data to be dynamic, so I can't just do > text = forms.CharField(widget = forms.Textarea, initial = 'sometext') > > I assume I can do some thing along the lines of overriding __init__ > for this form, passing the requored value from the view function and > then using something like > text = forms.CharField(widget = forms.Textarea, initial = > self.page.text) > I just can't get this to work? Any place where I can look for dynamic > values to initial? > > On Jan 6, 2:38 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Sun, 2008-01-06 at 01:32 -0800, shabda wrote: > > > I have a form, to which I want to pass some data when it is first > > > dipalyed, > > > My form is, > > > class EditPage(forms.Form): > > > text = forms.CharField(widget = forms.Textarea) > > > edit_summary = forms.CharField() > > > > In my view I bind data to this form as > > > if request.method == 'GET': > > > page = Page.objects.get(slug = slug) > > > edit_form = forms.EditPage({'text':page.current_revision.wiki_text}) > > > > Since this is a edit page, we need to display the previous data, but > > > the edit_summary field must be empty. However as soon as I bind any > > > thing to the form the validation fires and so in the template errors > > > are displayed, as form.errors is not empty. We can not se form.errors, > > > as that field is Immultable. SO how do I add data to the form when it > > > is first displayed? > > > You need to use the "initial" parameter for supplying initial data. > > Seehttp://www.djangoproject.com/documentation/newforms/#initialforthe > > details. > > > Regards, > > Malcolm > > > -- > > Success always occurs in private and failure in full > > view.http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---