Check the docs for "initial".
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
at python level you can do it like this (untested):
def myview(request, ...):
form=MyForm(..., initial={'email': request.user.email})
or
form.fields['email'].initial=request.user.email
shogu...@googlemail.com schrieb:
> Hi Thomas,
>
> Thanks for your quick reply!
>
> I had a look at the docs, but it seems I have to enter the initial
> values at the Form definition level. However, I am interested in
> entering dynamic data depending on who is viewing the form. For
> instance, in my case I want the user's email address to be displayed
> in the form when they view the page. Since the form definition doesn't
> have access to the request object, I presume this is not possible.
>
>
--
Thomas Guettler, http://www.thomas-guettler.de/
The form is used to create a new object in the database. What I've
found as the main problem is that when I display the form for the
first time, if it's bound it throws validation errors (because I don't
want to pre-populate all the required fields) and if it is not bound
it just doesn't display the pre-populated data.
My workaround at the time is to pass a flag to the template so it
doesn't show the errors but I still don't think that is the best way
to do it.
Any help would be appreciated.
If you create tHe Form ala
form = Form( initial={'user': request.user})
it should prepopulate the field and not throw validation errors.
if on the other hand you create the form like:
form = Form({'user': request.user})
you bind the form and it validates on output.
adi
form = CargaRecetaForm(initial={'obra_social':str(os.siglaosocial),
'plan':str(plan.descplan), 'CU': str(numfar), 'NrodeOrden':
str(sigord)})
contexto = RequestContext(request, {'form':form})
return render_to_response('carga_page2.html', contexto)
--
Hernan Olivera