From 765e8b46ec489b8ff895603ed826a40ec759eb3e Mon Sep 17 00:00:00 2001 From: Viner Abubakirov Date: Sat, 3 Jan 2026 13:11:34 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D0=BF=D0=B0=D0=B3=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- music_storage/music/views.py | 40 +++++++++++++------ .../templates/components/album_list.html | 38 +++++++++--------- .../templates/components/artist_list.html | 36 ++++++++--------- .../templates/components/pagination.html | 11 +++++ .../templates/components/track_list.html | 37 +++++++++-------- music_storage/templates/music/album_list.html | 5 ++- .../templates/music/artist_list.html | 5 ++- music_storage/templates/music/track_list.html | 6 ++- 8 files changed, 105 insertions(+), 73 deletions(-) create mode 100644 music_storage/templates/components/pagination.html diff --git a/music_storage/music/views.py b/music_storage/music/views.py index b669dfe..11946fc 100644 --- a/music_storage/music/views.py +++ b/music_storage/music/views.py @@ -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): diff --git a/music_storage/templates/components/album_list.html b/music_storage/templates/components/album_list.html index b5b3c52..812e583 100644 --- a/music_storage/templates/components/album_list.html +++ b/music_storage/templates/components/album_list.html @@ -2,25 +2,23 @@ -
-
- {% for album in albums %} - + {% empty %} +

No albums available.

+ {% endfor %}
\ No newline at end of file diff --git a/music_storage/templates/components/artist_list.html b/music_storage/templates/components/artist_list.html index ec22ab7..2194f33 100644 --- a/music_storage/templates/components/artist_list.html +++ b/music_storage/templates/components/artist_list.html @@ -2,26 +2,24 @@ -
-
- {% for artist in artists %} - + {% empty %} +

No artists available.

+ {% endfor %}
\ No newline at end of file diff --git a/music_storage/templates/components/pagination.html b/music_storage/templates/components/pagination.html new file mode 100644 index 0000000..087f9bf --- /dev/null +++ b/music_storage/templates/components/pagination.html @@ -0,0 +1,11 @@ +{% if page_obj.has_previous %} + ← Назад +{% endif %} + + + Страница {{ page_obj.number }} из {{ page_obj.paginator.num_pages }} + + +{% if page_obj.has_next %} + Вперёд → +{% endif %} \ No newline at end of file diff --git a/music_storage/templates/components/track_list.html b/music_storage/templates/components/track_list.html index e9a33cc..0c060cd 100644 --- a/music_storage/templates/components/track_list.html +++ b/music_storage/templates/components/track_list.html @@ -1,23 +1,22 @@ {% load static %} -
-
    - {% if tracks %} - {% for track in tracks %} -
  • -
    -

    {{ track.title }}

    -

    Исполнитель: {{ track.album.artist }}

    -
    -
  • - {% endfor %} - {% else %} -
    - -

    Нет добавленных треков

    + +
      + {% if tracks %} + {% for track in tracks %} +
    • +
      +

      {{ track.title }}

      +

      Исполнитель: {{ track.album.artist }}

      - {% endif %} -
    -
    -{% include 'components/player.html' %} + + {% endfor %} + {% else %} +
    + +

    Нет добавленных треков

    +
    + {% endif %} +
+ diff --git a/music_storage/templates/music/album_list.html b/music_storage/templates/music/album_list.html index f21c728..fccf853 100644 --- a/music_storage/templates/music/album_list.html +++ b/music_storage/templates/music/album_list.html @@ -3,5 +3,8 @@ {% block content %}

Album List

-{% include 'components/album_list.html' with albums=albums %} +
+ {% include 'components/album_list.html' %} + {% include 'components/pagination.html' %} +
{% endblock %} \ No newline at end of file diff --git a/music_storage/templates/music/artist_list.html b/music_storage/templates/music/artist_list.html index 3f3fa13..82e7620 100644 --- a/music_storage/templates/music/artist_list.html +++ b/music_storage/templates/music/artist_list.html @@ -3,5 +3,8 @@ {% block title %}Artist List{% endblock %} {% block content %}

Artist List

-{% include 'components/artist_list.html' with artists=artists %} +
+ {% include 'components/artist_list.html' with artists=artists %} + {% include 'components/pagination.html' with page_obj=page_obj %} +
{% endblock %} diff --git a/music_storage/templates/music/track_list.html b/music_storage/templates/music/track_list.html index 174857c..5e5b95e 100644 --- a/music_storage/templates/music/track_list.html +++ b/music_storage/templates/music/track_list.html @@ -1,5 +1,9 @@ {% extends 'base.html' %} {% block content %} -{% include 'components/track_list.html' %} +
+ {% include 'components/track_list.html' %} + {% include 'components/pagination.html' %} + {% include 'components/player.html' %} +
{% endblock %}