how to pass the ID of a slected item in a list to ORM

29 views
Skip to first unread message

Gerald Brown

unread,
Jun 15, 2018, 12:46:53 PM6/15/18
to Django users
Greetings:

I have a form with a listbox that has people's names and their ID from the database.  I am trying to get the ID from that list for the selected person so I can use it in ORM statements: I.E. v1 = Visit.objects.filter(person_id = ??) where ?? is the ID from the select list.

Has anyone had any experience on how I can accomplish this?

Thanks.

Anthony Anonde

unread,
Jun 15, 2018, 2:09:29 PM6/15/18
to Django users
Sorry your question is a bit complicated, you have a form that contains a list of names and id, what data types are they contain in? Understand how the list box is structured will help to give you a better ans

C. Kirby

unread,
Jun 15, 2018, 2:29:57 PM6/15/18
to Django users
So you have a
<select>
 
<option>A</option>
  <option>B</option>
  <option>C</option>
</select>

If you make your option tags look like
<option value="{{person.person_id}}">{{person.name}}</option>

The submitted value for the field will be the patient_id, which you then use in your filter statement.

Gerald Brown

unread,
Jun 16, 2018, 1:41:36 AM6/16/18
to django...@googlegroups.com
The ID is an integer as it is the ID for the table. The name is a VARCHAR.

I have had this same problem in the past with other programming
languages.  How to get my head around how to get the ID for a selected item.

Gerald Brown

unread,
Jun 16, 2018, 2:07:01 AM6/16/18
to django...@googlegroups.com

When I inspect the object in Firefox that is what it looks like because it is generated by Django. Does the user have to select an item and then submit it in order for me to get the ID?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd054ed4-8761-415d-adaf-07bfc144956d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

C. Kirby

unread,
Jun 18, 2018, 8:17:11 PM6/18/18
to Django users
Yes

Gerald Brown

unread,
Jun 22, 2018, 12:10:19 PM6/22/18
to django...@googlegroups.com

Thanks for the reply.

Reply all
Reply to author
Forward
0 new messages