Обновил шаблон для album_list.html и добавил функцию для cover_image в модели Album

This commit is contained in:
Viner Abubakirov
2026-01-02 15:29:09 +05:00
parent e67f5d5689
commit c36e236c3f
3 changed files with 81 additions and 10 deletions

View File

@@ -1,6 +1,14 @@
from django.db import models
from core.models import BaseModel
import os
import uuid
def album_cover_upload_to(instance, filename):
ext = filename.split(".")[-1]
return os.path.join("album_covers", f"{uuid.uuid4()}.{ext}")
class Artist(BaseModel):
name = models.CharField(max_length=200)
@@ -12,7 +20,9 @@ class Artist(BaseModel):
class Album(BaseModel):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE, related_name="albums")
name = models.CharField(max_length=200)
cover_image = models.ImageField(upload_to="album_covers/", null=True, blank=True)
cover_image = models.ImageField(
upload_to=album_cover_upload_to, null=True, blank=True
)
def __str__(self):
return f"{self.artist} - {self.name}"