I'm trying to change a Boolean value in my database by clicking on an image in Django I add my View, my Model and my html.
View
def reservacion(request):
estatus = Asientos.objects.get(asiento=Aqui me gustaria colocar el valor del id del html de la imagen)
if estatus.status == False:
estatus.status = True
estatus.save()
elif estatus.status == True:
estatus.status = False
estatus.save()
else:
estatus.status = True
estatus.save()
return render(request,"first_app/reservacion.html")
model
class Reserva(models.Model):
mesa = models.CharField(max_length=2,primary_key=True)
asiento = models.ForeignKey(Asientos)
def __str__(self):
return self.mesa
html
{% if estatus.status == True %}
<div id = m1 class="col"><a href="{% url first_app:enreserva %}"><img class="d-block w-100" src="{%static "/img/s6.jpg" %}" alt=""></a></div>
{% else %}
<div id = m1 class="col"><a href="{% url first_app:enreserva %}"><img class="d-block w-100" src="{%static "/img/sn6.jpg" %}" alt=""></a></div>
{% endif %}
At the moment my view works if I add a status value but I would like to assign an existing one and I have not achieved it, besides the html route does not work this way and I need to click on the view and change the value of the image, additional my if in the html does not make the comparison always gives me a False value even when it makes the change in the database.