Добавил release_date в Album

This commit is contained in:
Viner Abubakirov
2026-01-04 23:44:41 +05:00
parent 9d8f881b7a
commit 2e63f86484
4 changed files with 33 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 6.0 on 2026-01-04 18:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('music', '0009_album_preview_image'),
]
operations = [
migrations.AddField(
model_name='album',
name='release_date',
field=models.PositiveSmallIntegerField(default=0),
),
]

View File

@@ -38,6 +38,7 @@ class Artist(BaseModel):
class Album(BaseModel):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE, related_name="albums")
name = models.CharField(max_length=200)
release_date = models.PositiveSmallIntegerField(default=0)
cover_image = models.ImageField(
upload_to=album_cover_upload_to, null=True, blank=True
)

View File

@@ -17,11 +17,13 @@ class TrackListView(ListView):
def get_queryset(self):
return (
super().get_queryset()
super()
.get_queryset()
.select_related("album", "album__artist")
.order_by("id")
)
class ArtistListView(ListView):
model = Artist
template_name = "music/artist_list.html"
@@ -35,7 +37,14 @@ class ArtistListView(ListView):
class ArtistDetailView(django_views.View):
def get(self, request: HttpRequest, pk: int, *args, **kwargs):
artist = get_object_or_404(Artist, id=pk)
return render(request, "music/artist_detail.html", {"artist": artist})
return render(
request,
"music/artist_detail.html",
{
"artist": artist,
"albums": artist.albums.all().order_by("-release_date"),
},
)
class AlbumListView(ListView):

View File

@@ -5,5 +5,5 @@
{% block content %}
<h1>{{ artist.name }}</h1>
<h2>Albums</h2>
{% include 'components/album_list.html' with albums=artist.albums.all %}
{% include 'components/album_list.html' %}
{% endblock %}