Saturday, May 14, 2011

form new versus edit

I have a "new" contact form. If I post it, and it has error, I found
(while debugging, not documented that I can find) that I can redraw
the submitted form data using form.name.data like this:

<input type="text" name="name" value="{{ form.name.data }}" />

But, if I use that same form model in my "edit" contact form,
form.name.data is None. Why is that?


In my new method I do:

form = ContactForm( request.POST )


In my edit method I do:

contact = Contact.objects.get( pk=id )
form = ContactForm( instance=contact )

But then the form contains none of the fields I'm expecting, form.name
simply isn't there so form.name.data throws an exception.


What am I doing wrong?

I'd really like to just have my one _form.html template included in
both my add.html and my edit.html templates. How can I do that when
the form doesn't even work the same between new versus editing?


Thanks.


--
Greg Donald
destiney.com | gregdonald.com

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate