Reputation: 3
Im trying to change a boolean value in django when I click an input image I think I already done it but now when I try to compare this boolean in my html it doesnt bring the correct value it always brings its as False (sn6.jpg)
View.py
def reservacion(request):
if request.method == "POST":
estatus = Asientos.objects.get(asiento=1)
if estatus.status == True:
estatus.status = False
estatus.save()
else:
estatus.status = True
estatus.save()
return render(request,"reservacion.html")
Models.py
class Reserva(models.Model):
mesa = models.CharField(max_length=2,primary_key=True)
asiento = models.ForeignKey(Asientos)
def __str__(self):
return self.mesa
html-- in here my if statements change the value of the boolean on my DB but it always shows the image in False (sn6.jpg)
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<div class="row">
{% if estatus.status == True%}
<div class="col"><input class="d-block w-100" type="image" src="{%static "/img/s6.jpg" %}" name="1" value=""></div>
{% else %}
<div class="col"><input class="d-block w-100" type="image" src="{%static "/img/sn6.jpg" %}" name="1" value=""></div>
{% endif %}
</form>
Am I missing something?, how can i get the other oimage when i click and submit the value?
Upvotes: 0
Views: 345
Reputation: 518
Two points:
render(request,"reservacion.html", {‘estatus’: estatus})
True
, this is enough : if estatus.status
Upvotes: 1