O
O
outsider_x2019-08-09 10:02:38
Django
outsider_x, 2019-08-09 10:02:38

How to set default value for MultipleChoiceField?

I have the following form in forms.py :

class TagForm(forms.Form):
    tags = forms.MultipleChoiceField()

And trying to show selection of tags list by inserting some default list:
def tag_select(request):
        form = TagForm(initial={'tags' : ['15', '16']})
        return render(request, '.html', context={"form" : form})

.html
{{ form.tags }}
The form renders correctly, but there is no list box by default. I tried to insert it in different forms, but still there is no list by default.
ps tried ModelMultipleChoiceField and pass QuerySet - works. But I need it to be named MultipleChoiceField

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-08-09
@deepblack

Have you looked here?
https://stackoverflow.com/a/4689141/2981702
https://stackoverflow.com/a/28518514/2981702
https://www.programcreek.com/python/example/58199/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question