2020-12-15 21:32:20 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
2021-07-09 19:51:55 +00:00
|
|
|
import random
|
|
|
|
from songs.models import Song
|
|
|
|
from idols.models import Idol
|
|
|
|
|
2020-12-15 21:32:20 +00:00
|
|
|
# Create your views here.
|
2021-07-10 13:41:17 +00:00
|
|
|
|
|
|
|
|
2020-12-15 21:32:20 +00:00
|
|
|
def index(request):
|
2021-07-10 13:41:17 +00:00
|
|
|
return render(request, "index.html")
|
|
|
|
|
2021-07-09 19:51:55 +00:00
|
|
|
|
|
|
|
def randomizer(request):
|
|
|
|
obj = {}
|
2021-07-10 13:41:17 +00:00
|
|
|
if "song_id" in request.GET:
|
|
|
|
obj['song'] = Song.objects.get(pk=request.GET['song_id'])
|
|
|
|
else:
|
|
|
|
song_ids = list(Song.objects.values_list('pk', flat=True))
|
2021-07-09 19:51:55 +00:00
|
|
|
song_id = random.choice(song_ids)
|
|
|
|
obj['song'] = Song.objects.get(pk=song_id)
|
2021-07-10 13:41:17 +00:00
|
|
|
if "num" in request.GET:
|
|
|
|
obj['num'] = request.GET['num']
|
|
|
|
idol_ids = list(Idol.objects.values_list('pk', flat=True))
|
|
|
|
idol_selected_ids = random.sample(idol_ids, int(request.GET['num']))
|
2021-07-09 19:51:55 +00:00
|
|
|
obj['idols'] = Idol.objects.filter(pk__in=idol_selected_ids)
|
2021-07-10 13:41:17 +00:00
|
|
|
return render(request, "randomizer.html", obj)
|