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