LORDCHANNEL2.0/utils/random_media.py

20 lines
776 B
Python
Raw Normal View History

2021-03-13 18:36:50 +00:00
from Film.models import Film
from SerieTV.models import SerieTV
from Anime.models import Anime
import random
def random_media():
film = Film.objects.all()
serietv = SerieTV.objects.all()
anime = Anime.objects.all()
if film.count() >= 8 and serietv.count() >= 8 and anime.count() >= 8:
random_film = random.sample(list(film),8)
random_serietv = random.sample(list(serietv),8)
random_anime = random.sample(list(anime),8)
else:
random_film = random.sample(list(film),4)
random_serietv = random.sample(list(serietv),4)
random_anime = random.sample(list(anime),4)
random_media_context = {"random_film":random_film,"random_serietv":random_serietv,"random_anime":random_anime}
return random_media_context