我正在尝试为我的项目实施更新功能。我正在使用2种表格更新记录,一种用于“问题”,另一种用于“响应”。
views.py:
@login_required(login_url="/login/")
def update(request, id):
resp = Response.objects.select_related('Question').get(pk=id)
quest = Question.objects.get(pk=resp.Question_id)
qform = QuestionForm(request.POST or None, instance=quest)
rform = ResponseForm(request.POST or None, instance=resp)
rf = rform
qf = qform
if qform.is_valid() and rform.is_valid():
qf = qform.save()
rf = rform.save(commit=False)
rf.Question = qf
rf = rform.save()
return redirect('../../search_es20')
return render(request, 'app/update.html', {
"rform": rf,
"qform": qf,
})
当我尝试更新记录时,它将带我到更新页面,但“问题和响应”字段显示为空白。
但是通过检查,它显示出文本区域中有文本:
<textarea name="Statement" cols="180" rows="1" required="" id="id_Statement">Non-functional (Automated Testing)</textarea>
如何使它出现在字段中?