I concur with Oliver.

Obviously if your dynamic user_name is a variable, it would look like
this:

form=MyForm(initial={'user_name':user_name})

And of course, this is written in the view.

On May 12, 2:41 pm, oliver <[EMAIL PROTECTED]> wrote:
> I do it like this:
>
> def frommagic(request):
>   if request.POST:
>     process form
>   else:
>     from = MyForm(initial={'user_name': 'John Doe' })
>
> works well in our quite complex 6 step booking form ..
>
> On May 12, 9:37 pm, Mike Chambers <[EMAIL PROTECTED]> wrote:
>
> > I have a project where I need to dynamically set the default values for
> > a form field. I have come up with the following solution, but wanted to
> > check here to see if anyone saw any problems with it:
>
> > ----MyForm----
> > class MyForm(forms.Form):
> >         user_name = forms.CharField(min_length=1, max_length=60)
>
> >         def set_initial(self, property, value):
> >                 self.fields[property].initial = value
> >         #end set_initial
> > --------------
>
> > form = MyForm()
> > form.set_initial('user_name', "John Doe")
>
> > -------
>
> > Anyone see any issues with that approach? Or am I missing something
> > already built in?
>
> > mike chambers
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to