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


i creating app in django , have form field 'person' foreignkey field. so, when run application appears form correctly showing me combobox lets me select 'person' object want. problem when try catch information in view.

i send data post method, so, when try value of selected 'person' object in view next:

 selected_person = request.post['person'] 

(person field name)

i surprised when tested value of variable 'selected_person' number (concretely, number of selected index of element in combobox).

my question is: how can object value of selected element in combobox?

than much!

no, primary key of person object in database. can via person.objects.get(pk=selected_person).

but should using django form, give person object via form.cleaned_data['person'].

also note, clarity, select field, or drop-down, not combobox; combobox desktop widget has both drop-down , edit field.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -