14 lines
302 B
Python
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) |