Добавил черновой вариант пагинации и переделал шаблоны
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django import views as django_views
|
||||
from django.views.generic import ListView
|
||||
from django.shortcuts import render
|
||||
from django.http.request import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
@@ -8,16 +9,27 @@ from music.models import Artist
|
||||
from music.models import Album
|
||||
|
||||
|
||||
class TrackListView(django_views.View):
|
||||
def get(self, request: HttpRequest, *args, **kwargs):
|
||||
tracks = Track.objects.all().select_related("album__artist",).order_by("id")
|
||||
return render(request, "music/track_list.html", {"tracks": tracks})
|
||||
class TrackListView(ListView):
|
||||
model = Track
|
||||
template_name = "music/track_list.html"
|
||||
context_object_name = "tracks"
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
super().get_queryset()
|
||||
.select_related("album", "album__artist")
|
||||
.order_by("id")
|
||||
)
|
||||
|
||||
class ArtistListView(django_views.View):
|
||||
def get(self, request: HttpRequest, *args, **kwargs):
|
||||
artists = Artist.objects.all()
|
||||
return render(request, "music/artist_list.html", {"artists": artists})
|
||||
class ArtistListView(ListView):
|
||||
model = Artist
|
||||
template_name = "music/artist_list.html"
|
||||
context_object_name = "artists"
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().order_by("id")
|
||||
|
||||
|
||||
class ArtistDetailView(django_views.View):
|
||||
@@ -26,10 +38,14 @@ class ArtistDetailView(django_views.View):
|
||||
return render(request, "music/artist_detail.html", {"artist": artist})
|
||||
|
||||
|
||||
class AlbumListView(django_views.View):
|
||||
def get(self, request: HttpRequest, *args, **kwargs):
|
||||
albums = Album.objects.all().order_by("id")
|
||||
return render(request, "music/album_list.html", {"albums": albums})
|
||||
class AlbumListView(ListView):
|
||||
model = Album
|
||||
template_name = "music/album_list.html"
|
||||
context_object_name = "albums"
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().order_by("id")
|
||||
|
||||
|
||||
class AlbumDetailView(django_views.View):
|
||||
|
||||
Reference in New Issue
Block a user