form.fieldname.value ?

0 views
Skip to first unread message

mbdtsmh

unread,
Apr 21, 2008, 11:52:25 AM4/21/08
to django...@googlegroups.com

Hi all - being new to Django I've started to define my first template. The
issue that I am having is when I simply want to get a value from a form
object (rather than the whole <input .... </input> string).

I can get around this by passing in extra values in the render_to_response
command in the views.py file i.e.,

blah = get_object_or_404(mymodel, pk=id)
blah_date = blah.date

and then pass in blah_date to my template.

I thought though there may be a way of getting to the values from the form
object that I am passing into the template

form = BlahForm(request.POST,instance=blah) # BlahForm is defined in
models.py

so in the template I could get values from the form object ie..,
form.date.value (or something similar)

is there a way to do this or do I have to pass in values from the views.py
file as I having to do at the moment.

Hope this makes sense?!

Regards
--
View this message in context: http://www.nabble.com/form.fieldname.value---tp16808012p16808012.html
Sent from the django-users mailing list archive at Nabble.com.

Doug B

unread,
Apr 21, 2008, 12:23:18 PM4/21/08
to Django users
Unless something has changed since.96 you should be able to access
initial and bound data directly. They are stored in dicts on the form
object called 'initial' and 'data'

form.data.fieldname (this is pre-cleaned bound data)
form.cleaned_data.fieldname (post clean if valid)
form.initial.fieldname (values set for initial)
Reply all
Reply to author
Forward
0 new messages