Q:

How can I get the object value of a combobox in django view?

I am creating an app in django and to do that I have a form where the field 'Person' is a ForeignKey field. So, when I run the application it appears a form correctly showing me a combobox that lets me select the 'Person' object that I want. But the problem is when I try to catch the information in the view.
I send data with a POST method, so, when I try to get the value of the selected 'Person' object in the view I do the next:
 selected_person = request.POST['person']

(Person is the field name)
I was surprised when I tested that the value of the variable 'selected_person' is a number (concretely, the number of the selected index of the element in the combobox).
My question is: HOW CAN I GET THE OBJECT VALUE OF THE SELECTED ELEMENT IN THE COMBOBOX?
Than you so much!

A:

No, it is the primary key of the Person object in the database. So you can get it via Person.objects.get(pk=selected_person).
But really you should be using a Django form, which will then give you the Person object via form.cleaned_data['person'].
Also note, for clarity, this is a select field, or a drop-down, not a combobox; a combobox is a desktop widget that has both a drop-down and an edit field.

