steeldonutcollection/frontend/templatetags/random.py

14 lines
302 B
Python
Raw Permalink Normal View History

2022-05-05 15:40:57 +00:00
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)