Benedict Verheyen wrote: > Benedict Verheyen wrote: > <snip> > As expected, it works if i set the values in my view: > > action = get_object_or_404(Action, pk=action_id) > form=ActionForm(instance=action) > if request.method == 'POST': > form = ActionForm(request.POST, action) > if form.is_valid(): > edit_action=form.save(commit=False) > edit_action.call = action.call > edit_action.date_created = action.date_created > edit_action.id = action.id > edit_action.save() > form.save_m2m() > return HttpResponseRedirect(reverse(call_detail, > kwargs={"call_id": action.call.id})) # Redirect after POST > return render_to_response('management/action_edit.html', > {'form': form, 'action': action}, > context_instance=RequestContext(request)) > > I'm not sure if this is the best way to solve the problem. > > Also, it seems strange that one needs to add the action to the ActionForm > but yet, have to set the 3 missing fields anyway (call, date_created and id) > If i don't assign the id, then a new action is made instead of an old > one update. > > Could this be a bug? If not how come i need to manually set those fields > or else i get an error? > > Regards, > Benedict >
In finally found what was wrong in my code ! As you can see above, i used this line: form = ActionForm(request.POST, action) This needs to be: form = ActionForm(request.POST, instance=action) So because i didn't use the instance keyword, the extra values weren't set. Regards, Benedict -- 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.