On 3/2/07, grahamu <[EMAIL PROTECTED]> wrote:
>
>
> On Mar 1, 12:53 pm, "Honza Kr�l" <[EMAIL PROTECTED]> wrote:
>
> > > 1. Is there an easy way to get the new object created by form.save()?
> >
> > obj = form.save()
>
> Thanks, I finally saw that after perusing the django source code.
>
> > > 2. Is is true that one should not call form.save() if the form was
> > > instantiated from a class resulting from form_for_instance()?
> >
> > no, this is not true, if it were the case, why would the method be there?
>
> I agree with you; however, I was referencing the user "chasfs" who
> commented in:
>
> (http://groups.google.com/group/django-users/browse_frm/thread/
> cbbf169b6aaa3f39/3f08ba5b59feea3d?lnk=st&q=form_for_instance
> +form.save&rnum=6#3f08ba5b59feea3d)
>
> writing:
>
> "and finally, if you are using form_for_instance, to update an
> existing
> instance, you can't use the form.save - instead try something like
> this:
>   form = forms.form_for_instance(obj,
> formfield_callback=obj_callback)
> (request.POST)
>     if form.is_valid():
>       for i in form.clean_data:
>         obj.__setattr__(i, form.clean_data[i])
>       obj.save()
>       return HttpResponseRedirect(...)"
>

this is a relevant code from django.newforms.models, which is
responsible for handling the form_for_instance().save()

    for f in opts.fields:
        if not f.editable or isinstance(f, models.AutoField):
            continue
        setattr(instance, f.name, clean_data[f.name])

the only time it doesn't work is when you have a many2many field(s)
and use commit=False

> Thanks for your assistance Honza!
> Graham
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

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