0

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.

1 Answer 1

1

In your select box, pass a value for your options:

<option value="{{icas.filepath}}">{{ icas }}</option>
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. It was really that simple. Thank you so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.