2020-12-16 17:51:29 +00:00
|
|
|
from django.core.paginator import Paginator
|
2020-12-16 17:36:29 +00:00
|
|
|
from django.shortcuts import render, redirect
|
2020-12-15 21:32:20 +00:00
|
|
|
|
2020-12-16 17:36:29 +00:00
|
|
|
from .models import Song
|
2020-12-15 21:32:20 +00:00
|
|
|
# Create your views here.
|
2020-12-16 17:36:29 +00:00
|
|
|
def song_index(request):
|
|
|
|
songs = Song.objects.all()
|
2020-12-17 15:48:07 +00:00
|
|
|
objs = {}
|
|
|
|
if "q" in request.GET:
|
|
|
|
q = request.GET['q']
|
2020-12-17 15:59:22 +00:00
|
|
|
songs = Song.objects.filter(title__icontains=q) | Song.objects.filter(romanized_title__icontains=q)
|
2020-12-17 15:48:07 +00:00
|
|
|
objs['q'] = q
|
2020-12-16 17:51:29 +00:00
|
|
|
paginator = Paginator(songs, 100)
|
|
|
|
page_number = request.GET.get('page',1)
|
|
|
|
page_obj = paginator.get_page(page_number)
|
2020-12-17 15:48:07 +00:00
|
|
|
objs['page_obj'] = page_obj
|
|
|
|
return render(request,'songs/index.html',objs)
|
2020-12-16 17:36:29 +00:00
|
|
|
|
|
|
|
def song_id(request, id):
|
|
|
|
song = Song.objects.filter(id=id)[0]
|
|
|
|
return redirect(song_show,id=song.id,title=song.title)
|
|
|
|
|
|
|
|
def song_show(request, id, title):
|
2021-01-09 13:30:51 +00:00
|
|
|
song = Song.objects.filter(id=id)[0]
|
|
|
|
return render(request,'songs/show.html',{'song':song})
|