hln
hln

Reputation: 1106

initial multiple values in select fields

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

Answers (1)

Samuele Mattiuzzo
Samuele Mattiuzzo

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.POSTcontains a value for keyword, you'll lose your initial values.

Upvotes: 1

Related Questions