On Feb 4, 11:56 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Feb 4, 8:13 am, "James Bennett" <[EMAIL PROTECTED]> wrote: > > On Feb 4, 2008 6:43 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > as you can see, I hide the primary and foreign key fields (yes, I am > > > aware of the security implications: can we fix the real problem > > > please ;-) > For the record the simple solution to this problem is as follows. I included the primary and foreign key fields on the form due to a misunderstanding of forms processing. When a form is used to *create* a model instance either it has to onclude all mandatory columns or it has to be saved with commit=False, then the resulting model instance has to have the missing columns added before it is saved.
Fortunately this does not apply to update, where it *is* possible to update a subset of the fields. I therefore changed the Answer ModelForm definition to class AnswerForm(forms.ModelForm): class Meta: model = Answer fields = ['anstext', 'ansresult', 'ansseq'] and the view to def answer(request, domid, quedqno, ansseq, ansid): question_no = "%s-%s" % (domid, quedqno) if request.method == 'POST': answer = Answer.objects.get(pk=ansid) form = AnswerForm(request.POST, instance=answer) if form.is_valid(): answer = form.save() return HttpResponseRedirect("/edit/question/%s/%s/" % (domid, quedqno)) else: domain = Domain.objects.get(pk=domid) question = Question.objects.get(quedomid=domain.domid, quedqno=quedqno) answer = Answer.objects.get(pk=ansid) form = AnswerForm(instance=answer) return render_to_response("answer.html", locals(), RequestContext(request)) and all was well. Further, nobody was ever going to 'hack me", as the site is a purely experimental one. None the less I am glad to have discovered the correct way to solve this problem. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---