Hi Malcolm

Thanks for your reply. I have done a bit of reading/experimentation
since my post and thought what you have said might be the case. I will
have a look at your suggestions.

However, I think I may be on the wrong track. What I want to do is
create a custom form (ie SurveyForm) to both add new records and edit
existing records. I have a save method on Survey (in models.py) which
saves createdBy, createdDate, lastModifiedBy and lastModifiedDate -
these will not be in form. I have been modifiying my code as suggested
in a posting (Newforms practice (common situation) ) but obviously
don't quite understand the entire thing.

Is there a better way of doing this? There seem to be lots of
reference to creating custom forms being easy but I think I am missing
something basic.


Regards

Catriona

On Oct 15, 5:49 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-10-11 at 17:34 -0700, Cat wrote:
> > Hello
>
> > Can anyone tell me why when I get to the line - form =
> > InstanceForm(request.POST) in the following view (stepping through the
> > code), I get a Type Error SurveyForm object is not callable. My
> > understanding is that it should be as it subclasses Form
>
> > def addEditSurvey(request, id = None):
>
> >    if id is not None:
> >            instance = Survey.objects.get(id=id)
> >            InstanceForm = SurveyForm(instance = instance)
> >    else:
> >            InstanceForm = SurveyForm()
>
> This line (and the similar one two lines earlier) creates an instance of
> the SurveyForm class. So InstanceForm isn't a class object, it's an
> instance of a class.
>
>
>
> >    if request.method == 'POST':
> >            form = InstanceForm(request.POST)
>
> This line would only make sense if either (a) InstanceForm had a
> __call__ method or (b) InstanceForm was a class object and so had a
> constructor. Neither of these is true. You are writing code as if
> InstanceForm was meant to be a class object -- and that is how the
> Django examples all look -- but it isn't (see above).
>
> If you want to create a class object that is based on things like the
> "instance" parameter, you need to look at Python meta-programming. This
> can be a fairly confusing area (because, by it's very nature, it's very
> abstract). However, for simple cases, it's not too bad. Have a look at
> django.newforms.models.form_for_model() for an example of creating a
> class object based on parametrised input.
>
> Regards,
> Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to