I've been looking for a solution for this for so long, but still can't find it. I have a large form in my template, which actually consists of a bunch of model forms. One field in this large form is not part of the form, but represents one dynamic drop-down menu that is populated from a table called "Institutions" in views.py as such: Institutions.objects.all ()
Here is the part from views.py:
def submission_form(request): institutions = Institution.objects.all() if request.method == 'POST': abstractform = AbstractForm(request.POST) authorform = AuthorForm(request.POST) # Here I want code: if selected institution is this, then do that if abstractform.is_valid() and authorform.is_valid() new_abstract = abstractform.save() new_author = authorform.save() else: return render(request, 'records/submission_form.html', {'abstractform': abstractform, 'authorform': authorform, 'institutions':institutions })
This is revealed in my template:
<select id="ddlInstititions"> <option value="%">---------</option> {% for entry in institutions %} <option value="{{ entry.id }}">{{ entry.name }}</option> {% endfor %} </select>
My question is: is it possible to pass the selected name entry.name to the view so that I can use it there? If not, what do you recommend doing instead?
Any help would be greatly appreciated!
django
user2966495
source share