Re: Error: 'PersonForm' object is not callable

2009-01-23 Thread waltbrad



On Jan 23, 7:19 am, bruno desthuilliers
 wrote:
> On 23 jan, 06:29, waltbrad  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
-~--~~~~--~~--~--~---



Re: Error: 'PersonForm' object is not callable

2009-01-23 Thread bruno desthuilliers

On 23 jan, 06:29, waltbrad  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-save-method

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

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Error: 'PersonForm' object is not callable

2009-01-22 Thread waltbrad



On Jan 23, 1:47 am, Alex Koshelev  wrote:
> You don't need to "call" form second time:
>
>         pForm = PersonForm(request.POST.copy(), instance=p)
>
> And pForm is the ready to use instance of form.
>
Thanks for that.  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.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Error: 'PersonForm' object is not callable

2009-01-22 Thread Alex Koshelev
You don't need to "call" form second time:

pForm = PersonForm(request.POST.copy(), instance=p)

And pForm is the ready to use instance of form.


On Fri, Jan 23, 2009 at 8:29 AM, waltbrad  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,
>
> if request.method == 'POST':
> if request.POST['submit'] == 'update':
>  message = 'Update Request for %s.' % p.name
>  pForm = PersonForm(instance=p)
>  c=pForm(request.POST.copy())
>
> 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)
>  f = PersonForm(request.POST.copy())
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Error: 'PersonForm' object is not callable

2009-01-22 Thread waltbrad

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,

if request.method == 'POST':
 if request.POST['submit'] == 'update':
  message = 'Update Request for %s.' % p.name
  pForm = PersonForm(instance=p)
  c=pForm(request.POST.copy())

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)
  f = PersonForm(request.POST.copy())

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---