I have spent too much time on this problem and am beginning to think that it can’t be done in Django. I am pulling a list of pathogen names from a postgres database to a drop down box. The user selects the pathogen, which requires the id to be passed back through django to the database for further retrieval of more data. Please see
http://dpaste.com/119358/ for the drop down code.
The problem is that the select id = statement is above the point where the form retrieves the pathology id. The django statements must be placed at this point or the drop down doesn’t work. Has anyone written something similar and found a solution?
Max
The id of the select tag in your HTML does not need to have any knowledge of your pathology records. Your code is correct, except for the lack of closing select tag.
Your Django view that is mapped to the /pathology/ action URL needs to handle the POST method and pull the pathology id out of the request like so:
Now you can look that object up in your database by its id and generate a new page/form or whatever business logic you need to do with it.
The dictionary key that you need to use in the request.POST[‘…’] call is based on the name you’ve given your select element, in this case ‘pathology’.