On Jan 23, 7:19 am, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 23 jan, 06:29, waltbrad <waltb...@hotmail.com> wrote:
>
> > Hi folks. PersonForm is a modelform.  I'm trying to validate data by
> > calling an instance of PersonForm.  (This is from Sam's 24 hour, and
> > I've modified the example to accommodate the 1.0 changes.)  So,
>
> NB : Alex already gave you the practical solution, but I thought a
> couple explanations migh help !-)
>
> > if request.method == 'POST':
> >      if request.POST['submit'] == 'update':
> >           message = 'Update Request for %s.' % p.name
> >           pForm = PersonForm(instance=p)
>
> This creates an instance of the PersonForm class. If you don't know
> Python : Python's classes are objects, and the call operator is used
> for instanciation (no 'new' operator needed).
>
> >           c=pForm(request.POST.copy())
>
> and this tries to call the PersonForm instance.
>
>
>
> > And I get the error alluded to in the Subject line.
>
> >  The author has
> > something similar:
>
> > if request.method == 'POST':
> >      if request.POST['submit'] == 'update':
> >           message = 'Update Request for %s.' % p.name
> >           PersonForm = forms.form_for_instance(p)
>
> This used to dynamically create a form *class* from the instance (and
> it's model of course).
>
> >           f = PersonForm(request.POST.copy())
>
> And this was instanciating the form class.
>
> """
> Would you know off hand where in the documentation I
> could find that? I looked around but just couldn't find much on the
> request.POST.copy function or it's use in modelforms.
> """
>
> wrt/ passing both request.POST (or whatever other data mapping) and an
> instance, you'll find an example here:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
>
> wrt/ the 'copy' method, it's documented 
> here:http://docs.djangoproject.com/en/dev/ref/request-response/#id1
>
> Using request.POST.copy() instead of request.POST is advised whenever
> the callee might modify it's input (Python doesn't copy objects when
> they are passed to functions).
>
> HTH

thankyou, bruno.  I know a bit about python. Not as much as I would
like. So, I'll be re-reading this post and the docs you site, till it
sinks in a bit.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to