Le samedi 27 mars 2010 19:23:04, Daniel Roseman a écrit : > On Mar 27, 4:34 pm, Thierry Chich <thierry.ch...@gmail.com> wrote: > > 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 ? > > No, this is expected and documented behaviour. If the POST doesn't > contain a value for a particular model field, that field is set to > blank. This is because an empty HTML field is not included in an POST, > exactly as if the field wasn't on the form at all. > This make sense. It is obvously a good reason.
> If you don't want this to happen, exclude the domaine field from the > form altogether via the modelform Meta 'fields' or 'exclude' tuples. OK. I can also put an hidden field in my form. I will evaluate what is the better option for me. Thanks very much. 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.