My question is the following one ... I have a select that is a foreign key, and at the same time it has another foreign key, and what I want to do is select a data of the first select and that the second select changes its content depending on the first select
My code
Models.py
correspondence, are more data but I do not put them
class corresp(models.Model):
Secretaria=models.ForeignKey(secretarias, null=True, blank=False)
Unidad=models.ForeignKey(unidad, null=True, blank=False)
Models.py
of User
class secretarias(models.Model):
nombre_secretaria=models.CharField(max_length=80)
ubicacion=models.CharField(max_length=100)
def __unicode__(self):
return '{}'.format(self.nombre_secretaria)
class unidad(models.Model):
nombre_unidad = models.CharField(max_length=120)
Secretaria= models.ForeignKey(secretarias, null=True, blank=True)
File code views.py
def corresp_crear(request):
if request.method == 'POST':
form = CorrespondenciaForm(request.POST or None, request.FILES or None)
if form.is_valid():
c = form.save(commit=False)
c.user = request.user
c.save()
messages.success(request, 'Correspondencia creada correctamente .')
return redirect('correspondencia:corresp_listar')
else:
form = CorrespondenciaForm()
return render(request, 'registrarCorrespondencia/formulario1.html', {'form': form})
Part of the file code formulario1.html
<div class="well" style="overflow: auto">
<label>Destino por Areas</label><br>
<div class="col-md-6">{{ form.Secretaria.label}} {{ form.Secretaria}}</div>
<div class="col-md-6"> {{ form.Unidad.label}} {{ form.Unidad}}</div>
</div>