Good afternoon guys, I'm having a problem, I've registered for the django admin a video that should be sent to my template, but I need these videos to be sorted by the position
field I have in my models.py
in the bank
models.py :
from django.db import models
class Video(models.Model):
url = models.CharField(max_length=500, verbose_name='Link Embed')
title = models.CharField(max_length=255, verbose_name='Título')
description = models.TextField(max_length=1000, verbose_name='Descrição do video')
start_date = models.DateField(verbose_name='Estará disponível quando')
position = models.CharField(max_length=255 ,verbose_name='Qual posição')
def __str__(self):
return f'{self.title} {self.description} {self.start_date} - {self.url}'
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 %}
<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>
{% endfor %}
</div>
</body>
</html>
views.py :
from django.shortcuts import render, redirect
from datetime import date
from .models import *
from .forms import *
import requests
import random
def videos_list(request):
if 'lead_id' in request.session:
videos = Video.objects.all()
for video in videos:
print(video.titlle)
return render(request, 'videos-list.html', {'videos': videos})
return redirect('registrations:create_lead')