Answer the question
In order to leave comments, you need to log in
How to pass multichoicefiled values to initial?
The search form has a multiple choice field. It is necessary that the form, when clicking on the search, does not dump the previously entered values, for this, with the usual fields (select), I do this
if 'type_of_container' in request.GET and request.GET['type_of_container'] != '':
type_of_container = get_object_or_404(Typeofcontainer, id=request.GET['type_of_container'])
else:
type_of_container = None
form = CityChoiceForm(initial={
'type_of_container':type_of_container,
})
if 'type_of_body' in request.GET and request.GET.getlist('type_of_body') != '':
type_of_body = get_list_or_404(Typeofbody, id__in=request.GET.getlist('type_of_body'))
else:
type_of_body = None
form = CityChoiceForm(initial={
'type_of_body':type_of_body,
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question