In my models.py, I have two CharFields set that the Admin can log into and input. One has a friendly name and the other has a file path directory attached to it:
models.py
class IssuingCA (models.Model)
ICA_name = models.CharField(max_length=200)
filepath = models.CharField(max_length=200)
def __str__(self):
return self.ICA_name
In my views.py, I reference these fields so that I can use them in a drop-down <select> tag later:
views.py
from .models import IssuingCA
--snip--
"""This is the main page"""
def index(request):
issuers = IssuingCA.objects.order_by('ICA_name')
issuerOptions = {'issuers': issuers}
return render(request, 'index.html', issuerOptions)
--snip--
"""This is the results page"""
def results(request):
issuer = request.POST['selectedIssuer']
return render(request, 'results.html', {'issuer': issuer}
In my html code, I create a for loop for each ICA_name from my model.
index.html
--snip--
<select name="selectedIssuers">
{% for icas in issuers %}
<option>{{ icas }}</option>
{% endfor %}
</select>
results.html
--snip--
This is your result:<br />
<textarea rows="10" cols="200">{{ issuer }}</textarea>
--snip--
Right now, when I submit this data and return it via a simple post, it returns the ICA_name field I selected as expected. How can I get the result to show the matching filepath when the ICA_name is selected? I eventually want to pass this data (the filepath) onwards to more functions.