0

today I have encountered thing I do not really know why it happened.

I POSTed request with form that had MultipleModelChoiceField, in frontend I selected multiple of them (id 2 and 3), then in debug in PyCharm I wanted to see my POST request and saw this [see image].

With form.POST.get("people") I got >>> "3" as a result. After sanitizing data with After I accessed form.cleaned_data, the result was good, but I don't quite understand why did it happen, can someone please, try to explain what happened and why?

enter image description here

Thanks all!

  • Oooh, okay, don't know why devs did it in such puzzling way, but okay. Thanks! – DisplayedName Jul 19 '22 at 13:23
  • 1
    The point is that you will consistently want either a list or a string. For example in this case `people` currently has 2 value but what should happen when there is only 1 value posted? Should Django assume it to be a list or a string? Hence the decision is that all the values are actually internally a list but only the last value of the list is shown when accessed normally, if the list is needed then the explicit method for the same should be used. – Abdul Aziz Barkat Jul 19 '22 at 13:26

0 Answers0