2
I’m trying to put the names of the coordinators in the options of a select looking for the database, I already searched and it seems that there is another way to use select on Django, but it was not very clear, so I’m posting here my code to see if anyone can clear up my doubts.
This is the view part:
contexto ={
'coordenadores': Coordenador.objects.all()
}
...
return render(request, 'formDisciplina.html', contexto)
Here below is the template:
<p><label name='idcoordenador'>Coordenador: </label>
<select name='idcoordenador'>
<option>-----Selecione-----</option>
{% for a in coordenadores %}
<option values= {{ a.id }}> {{ a.name }} </option>
{% endfor %}
</select>
</p>
Look at this other question, I believe it satisfies your.
– Isael Sousa
I already searched but it was not very clear, I create the class in the same views ? And in the options I can insert the data of a comic with a for ?
– Jefferson Dong Min Kwak
The way you did it’s okay too. The way Isael pointed out is by using Django Forms that takes care of rendering the form elements for you but this takes a little time to understand how Forms work.
– André Duarte