Reputation: 1106
I have problem to initail multiple values in a select field
keyword=WorkerGenre.objects.filter(worker=customer.id)
keyword_list=[]
for k in keyword:
keyword_list.append(k.genre)
print k.genre
form=ChangeProfile(request.POST,initial={'keyword':keyword_list},)
It only initial one value in the multiple select field even I can see there are more than one value from
print k.genre
can anyone help me here
Upvotes: 0
Views: 74
Reputation: 11048
for k in keyword:
keyword_list.append(k.genre)
print k.genre
form=ChangeProfile(request.POST,initial={'keyword':keyword_list},)
Mind the indentation. If your request.POST
contains a value for keyword
, you'll lose your initial values.
Upvotes: 1