Malcolm Tredinnick wrote:
> Hi Michael,
> 
>  On Fri, 2007-03-02 at 16:08 +1100, Michael Lake wrote:
>> Im trying to understand newforms and comparing the newforms docs at 
>> http://www.djangoproject.com/documentation/newforms/ with "Using djangos 
>> newforms" at 
>> http://code.pui.ch/2007/01/07/using-djangos-newforms/ and Mike Cantelon's 
>> code at 
>> http://www.mikecantelon.com/?q=node/22

> Forms are view-level functions: a model does not need to be involved
> with forms, or accessible via the web, so you can usually arrange for
> things in models.py to be completely divorced from any knowledge of a
> "request" object and the like.
> 
> Forms, on the other hand, are your interface for user-input -- very much
> view functions. So put form handling code in views.py (or modules used
> by views.py).

That clicks. Good one understanding issue solved :-)

>>Philipp Keller's Example
>>------------------------
>>But then he defines this method:
>>def add_entry(request):
>>     EntryForm = forms.models.form_for_model(Entry)
>>     etc...
>>
>>and I'm not sure where this belongs ... in models.py or views.py.
> 
> 
> It's using "request" -- so it's a view.

I hadn't realised that if it takes a request then it should be in view.
So the request is coming from the user via the web server and it is handled by 
the 
parser that looks at url.py which passes it onto the appropriate view that then 
takes 
the request and acts upon it.
I'll now go through that article again with keeping in mind that it's dealing 
with a 
form so it should be in views.py.

>>What I have got so far
>>I have a small test form working using form_for_model and I have placed the 
>>class 
>>statement in models.py
....

> This looks reasonable. Are you having problems with it misbehaving, or
> just posting it in case there is some egregious mistake that jumps out?
The latter :-)

>>Also I'm confused on the save methods. Some exemples use form.save() and 
>>others 
>>define a save method under the model Class.
> 
> They serve slightly different purposes. A model class may have specific
> things that need to be done upon saving. 

Hence in Mike Kellers article he defines a save in the Class definition in 
models.py 
as he has self.added and self.changed as datetime things which need to be acted 
upon. 
A default form.save() would not do that I gather so he overrides it?

> Now, again, because forms and
> web-interfaces in general are not the only way to create and update
> model instances, some of the saving logic definitely belongs to the
> model class.
> 
> On the other side, when you automatically create a form from a model
> (using form_for_model(), it creates a special "save" method that is
> really a proxy for the model's save() method, but also checks that there
> are no validation errors in the form and updates the model with the
> forms inputs.
> 
> So form.save() for a form generated from form_for_model() is just a
> quick way to update and save from a form to a model. Does that clear
> things up at all, or just muddy the waters even further?

Clears thins up a bit. So if one can do with the save() from form_for_model 
then one 
is lucky - use it. Otherwise if you have something special like setting a 
datatime 
you have to use your own save().

> Newforms is not something that is immediately obvious, but once it does
> click, I think it seems much easier than the old forms way. I, for one,
> am pretty impressed with Adrian's design work here. It's worth
> persisting with trying to get them to work.

I have started a major project with Django after looking at a few alternatives 
like 
TurboGears or just writing my own cgi stuff. I'll certainly be persisting.
I'll be back next week with more questions :-)

Thanks
Mike

-- 
Michael Lake




--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to