Добавил поле "обложка" для модели Artist

This commit is contained in:
Viner Abubakirov
2026-01-02 15:31:32 +05:00
parent c36e236c3f
commit b8fc219f09
2 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# Generated by Django 6.0 on 2026-01-02 10:30
import music.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('music', '0006_album_cover_image'),
]
operations = [
migrations.AddField(
model_name='artist',
name='cover_image',
field=models.ImageField(blank=True, null=True, upload_to=music.models.artist_cover_upload_to),
),
migrations.AlterField(
model_name='album',
name='cover_image',
field=models.ImageField(blank=True, null=True, upload_to=music.models.album_cover_upload_to),
),
]

View File

@@ -10,8 +10,14 @@ def album_cover_upload_to(instance, filename):
return os.path.join("album_covers", f"{uuid.uuid4()}.{ext}")
def artist_cover_upload_to(instance, filename):
ext = filename.split(".")[-1]
return os.path.join("artist_covers", f"{uuid.uuid4()}.{ext}")
class Artist(BaseModel):
name = models.CharField(max_length=200)
cover_image = models.ImageField(upload_to=artist_cover_upload_to, null=True, blank=True)
def __str__(self):
return f"{self.name}"