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-16 17:51:29 +00:00
|
|
|
paginator = Paginator(songs, 100)
|
|
|
|
page_number = request.GET.get('page',1)
|
|
|
|
page_obj = paginator.get_page(page_number)
|
|
|
|
return render(request,'songs/index.html',{'page_obj':page_obj})
|
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):
|
|
|
|
song = Song.objects.filter(id=id,title=title)[0]
|
|
|
|
return render(request,'songs/show.html',{'song':song})
|