Сделал Плейлист и добавил рекомендацию на главную страницу

This commit is contained in:
Viner Abubakirov
2026-01-06 16:44:15 +05:00
parent 2e63f86484
commit 1df341006c
6 changed files with 136 additions and 10 deletions

View File

@@ -1,11 +1,10 @@
from django.urls import path
from core.views import index, sentry_debug
from core.views import IndexView
app_name = "index"
urlpatterns = [
path("", index, name="main_index"),
path("sentry-debug/", sentry_debug, name="sentry_debug"),
path("", IndexView.as_view(), name="main_index"),
]

View File

@@ -1,9 +1,19 @@
from django.shortcuts import render
from django.views.generic import View
from django.http.request import HttpRequest
from django.shortcuts import get_object_or_404
from music.models import RecommendationPlaylist
def index(request, *args, **kwargs):
return render(request, "index.html")
def sentry_debug(request):
division_by_zero = 1 / 0 # noqa
class IndexView(View):
def get(self, request: HttpRequest, *args, **kwargs):
if recommendation_playlist := RecommendationPlaylist.objects.filter(
is_actual=True
).first():
tracks = recommendation_playlist.tracks.all().select_related(
"album", "album__artist"
)[:10]
else:
tracks = []
return render(request, "index.html", {"tracks": tracks})