2017-12-05 15 views
1

私は次のように定義する]チェックボックスの選択から派生されたリストを持っている:保存する複数の行としてデータベースにリスト

checkedlist = request.GET.getlist('report_id') 

このリストは提出ビューにPOSTされます。

def submitted(request): 

    owner = User.objects.get (formattedusername=request.user.formattedusername) 
    requestsave = QVFormAccessRequest(ntname_id = owner.formattedusername, first_name = owner.first_name, last_name = owner.last_name, coid = owner.coid, facility = owner.facility, title = owner.title 
             ,report_id = request.POST.getlist('report_id')) 

    requestsave.save() 

問題は、データベースに保存しようとすると、自分のフィールドが正しいと指定されていることです。示すように、私が複数の行にそれを破るだろうかREPORT_IDにリストを投稿しようとして保存し、現在で

user information report_id 
user1234   1 
user1234   2 
user1234   3 
user1234   4 

:私は、リストのための私のREPORT_IDは、次のように私のデータベースに複数の行に格納したいです上記?私は次のエラーを取得する:

TypeError at /account/submitted/ 
int() argument must be a string, a bytes-like object or a number, not 'list' 

答えて

1

方法について

my_list = request.POST.getlist('report_id') 
for i in my_list 
    requestsave = QVFormAccessRequest(ntname_id = owner.formattedusername, first_name = owner.first_name, last_name = owner.last_name, coid = owner.coid, facility = owner.facility, title = owner.title, report_id = i) 
    requestsave.save() 
+0

私がしようとしていたまさに、あなたにBVMに感謝。 – student101

関連する問題