I'm writing an app that should list all teams from a local sports league inside a select box from which users can choose their favourite, however when I open the app everything looks good except that the select field shows only blank options. I know it's querying the DB correctly because it shows all 18 options inside the select box but they all appear blank and I get no error whatsoever.
Here is my model:
class Team(models.Model):
team_id = models.CharField(primary_key=True, max_length=3)
city = models.CharField(max_length=50)
name = models.CharField(max_length=50)
class Meta:
managed = False
db_table = 'team'
def __unicode__(self):
return self.team_id
my view:
@verified_email_required()
def crearcuenta(request):
equipos = Team.objects.all()
form = CuentaForm()
if request.method == "POST":
form = CuentaForm(request.POST)
if form.is_valid():
cuenta = form.save(commit=False)
cuenta.user = request.user
cuenta.equipo_favorito = request.POST.get("equipo", "")
cuenta.save()
return HttpResponseRedirect("/dashboard/")
context = ({
"equipos": equipos,
"form": form
})
return render(request, "teams/crearcuenta.html", context)
And lastly the html:
<div class="col-md-8 form-group mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<label for="Equipo" class="col-md-3 control-label mdl-textfield__label">Correo</label>
<div>
<select id="Equipo" name="equipo" class="selectpicker form-control" data-live-search="true">
<option>Seleccione uno</option>
{% for equipo in equipos %}
<option value="{{ equipos.team_id }}">{{ equipos.city }} {{ equipos.name }}</option>
{% endfor %}
</select>
</div>
</div>
Thanks!