我已经为表单创建了模型对象(不使用表单模型),并且希望用户在他们浏览不同的网页(视图)时逐步填写模型。为此,我显然需要通过视图传递模型对象。我已经尝试过会话,如下所示,但是模型对象不是JSON可序列化的。反正我能解决这个问题吗?
def home(request):
request.session['client'] = user_information(answers=personal_injury_answers())
return render(request, 'homescreen.html')
def firstStep(request):
client = request.session['client']
if request.method == 'POST':
preliminary_user_info = dict(QueryDict(query_string=request.body))
client.zipcode = int(preliminary_user_info['identifier'][1])
print(client.zipcode)
if preliminary_user_info['identifier'][0] == 'personal_injury':
return redirect('piuserform')
else:
return redirect('home')