These are my models
class Colegio(models.Model):
id_colegio = models.AutoField(primary_key=True)
nombre_colegio = models.CharField(max_length=100, blank=True, null=True)
def __unicode__(self):
return self.nombre_colegio
class Meta:
verbose_name_plural = "Colegios"
verbose_name = "Colegio"
ordering = ['nombre_colegio']
class Destino(models.Model):
id_destino = models.AutoField(primary_key=True)
nombre_destino = models.CharField(max_length=100)
def __unicode__(self):
return self.nombre_destino
class Meta:
verbose_name_plural = "Destinos"
verbose_name = "Destino"
ordering = ['nombre_destino']
class Tiempo(models.Model):
id_tiempo = models.AutoField(primary_key=True)
nombre_tiempo = models.CharField(max_length=50)
def __unicode__(self):
return self.nombre_tiempo
class Meta:
verbose_name_plural = "Tiempos"
verbose_name = "Tiempo"
ordering = ['nombre_tiempo']
class Costo(models.Model):
id_costo = models.AutoField(primary_key=True)
nombre_colegio = models.ForeignKey(Colegio)
nombre_destino = models.ForeignKey(Destino)
nombre_tiempo = models.ForeignKey(Tiempo)
valor = models.CharField(max_length=10)
def __unicode__(self):
return self.valor
class Meta:
verbose_name_plural = "Costos"
verbose_name = "Costo"
Here is my template where in a multiple selection button. The data is brought from the database.
<form method="post" id="signin-form_id">
{% csrf_token %}
<div class="col-sm-4">
<select name=eleccion1 class="form-control" style="margin-bottom: 15px;">
<option>Seleccione el Colegio</option>
{% for colegio in colegios %}
<option><p>{{colegio.nombre_colegio}}</p></option>
{% endfor %}
</select>
</div>
<div class="col-sm-3">
<select name=eleccion2 class="form-control" style="margin-bottom: 15px;">
<option selected destino="">Seleccione el Destino</option>
{% for destino in destinos %}
<option><p>{{destino.nombre_destino}}</p></option>
{% endfor %}
</select>
</div>
<div class="col-sm-3">
<select name=eleccion3 class="form-control" style="margin-bottom: 15px;">
<option selected tiempo="">Seleccione el Tiempo</option>
{% for tiempo in tiempos %}
<option><p>{{tiempo.nombre_tiempo}}</p></option>
{% endfor %}
</select>
</div>
<div class="col-sm-3">
<input type="text" name="tarifa">
</div>
<div class="form-actions">
<input type="submit" value="Costo" class="btn btn-success btn-rounded">
</div>
</form>
Here is my view
where I call the schools, destinations, times
class Cont(View):
login_url = '/'
template_name = 'listar_contratos.html'
def get(self, request):
listaColegios = Colegio.objects.all()
listaDestinos = Destino.objects.all()
listaTiempos = Tiempo.objects.all()
return render(request, self.template_name, {'colegios': listaColegios, 'destinos': listaDestinos, 'tiempos': listaTiempos})
What I want is that the field that is of type text
returns the value found in the models (Cost). In the table of Cost are the costs of each school with each destination and time.