steeldonutcollection/frontend/templatetags/random.py
2022-05-05 17:40:57 +02:00

14 lines
302 B
Python

from random import choices
from django import template
from backend.models import Video
register = template.Library()
@register.simple_tag
def random_videos(count=4):
ids = Video.objects.values_list("id", flat=True)
for vid in choices(ids, k=count):
yield Video.objects.get(id=vid)