I think I get the point.

If I write
        obj=MyModel()
        obj.domaine=request.session.get("domaine")
        form=MyModelForm(instance=obj)
        if form.is_valid():
                form.save()

It works (but I didn't populate my form)
So it seems that the data provided in data=request.POST are overwriting my 
domaine field.
It is really curious, because request.POST doesn't contain any reference to my 
field domaine

It's look like a bug, isn't it ?

Le samedi 27 mars 2010 15:54:53, Thierry Chich a écrit :
> Le samedi 27 mars 2010 14:39:40, Thierry Chich a écrit :
> > Hello all
> >
> > I have a problem to understand something. I could find some workaround
> >  easily, but I don't want it. I want to understand.
> >
> > So this if the situation. I have a modelForm (MyModelForm) that is build
> > on a model (MyModel) with one field mandatory (domaine - and it is a
> > Foreignkey). I don't want to show it to the user. I want it set in the
> > program
> >
> > I wrote this code in my view:
> >
> > if request.method == 'POST'
> >         obj=MyModel()
> >         obj.domaine=request.session.get("domaine")
> >         form=MyModelForm(request.POST,instance=obj)
> >     if form.is_valid():
> >            obj.save()
> 
> Smal mistake: it is form.save(), but it doesn't change nothing about the
> problem. It never enter in this cond. form is not valid.
> 
> > I was thinking that since obj already contain a 'domaine', it will not
> > complaining, but it is not the case. the form is considered as no valid
> > because of the domaine field. It is really disturbing for two reason:
> >
> > 1) with the debugger, I clearly see the domaine object in obj. I also see
> > a form.fieds.domaine that looks great.
> >
> > 2) In an other part, that work this time, I have something pretty
> > similar. I modified an obj already existant
> 
> Forget this point. It doesn't work. i don't know why. A regression, I
> believe....  So the idea doesn't seems work at all. If somebody know why
>  ...
> 
> > if request.method == 'POST':
> >         obj=get_object_or_404(MyModel,id=id)
> >         form=MyModelForm(request.POST,instance=obj)
> >         if form.is_valid():
> >             form.save()
> >
> > If some of you have an idea, I would be thanksfull.
> >
> > Thierry
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to