0
I have a list that I order by position
in my models.py
, but I have the field start_date
I want to use as a validator so that the item is visible or not. But it is not working:
py views.:
from django.shortcuts import render, redirect
from datetime import date
from .models import *
from .forms import *
import requests
def videos_list(request):
if 'lead_id' in request.session:
videos = Video.objects.order_by("position").all()
for video in videos:
print(video.title)
if video.start_date < date.today():
print(True)
show_video = True
else:
print(False)
show_video = False
return render(request, 'videos-list.html', {'videos': videos, 'show_video': show_video})
return redirect('registrations:create_lead')
in the console:
Programe ou seja programado - Episódio 01
True
Programa ou seja programado - Episódio 02
True
Programe ou seja programado - Episódio 03
False
I understood that at the end of the looping he leaves my variable show_video
as False and why mine template empty
video-list.html:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
{% for video in videos %}
{% if show_video %}
<div>
<h1>
{{video.title}}
</h1>
<iframe width="560" height="315" src="{{video.url}}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<p>
{{video.description}}
</p>
</div>
{% endif %}
{% endfor %}
</div>
</body>
</html>
But I don’t understand how to do it any other way ?
guy I’m your girlfriend fan, thank you so much for the explanation man, I was banging my head
– Raphael Melo De Lima