Изменил поле file в модели Track

This commit is contained in:
Viner Abubakirov
2026-01-03 00:50:18 +05:00
parent d1fbf4749d
commit 4266802e56
3 changed files with 30 additions and 3 deletions

View File

@@ -15,6 +15,14 @@ def artist_cover_upload_to(instance, filename):
return os.path.join("artist_covers", f"{uuid.uuid4()}.{ext}")
def track_upload_to(instance, filename):
return os.path.join(
"music",
f"album_{instance.album_id}",
filename,
)
class Artist(BaseModel):
name = models.CharField(max_length=200)
cover_image = models.ImageField(upload_to=artist_cover_upload_to, null=True, blank=True)
@@ -37,7 +45,7 @@ class Album(BaseModel):
class Track(BaseModel):
title = models.CharField(max_length=200)
album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name="tracks")
file = models.FileField(upload_to="music/")
file = models.FileField(upload_to=track_upload_to)
def __str__(self):
return f"{self.album.artist} - {self.title}"