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()
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
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 [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.