Изменил поле file в модели Track
This commit is contained in:
@@ -14,9 +14,9 @@ class TrackAdmin(admin.ModelAdmin):
|
||||
js = ("admin/js/upload_progress.js",)
|
||||
css = {"all": ("admin/css/upload_progress.css",)}
|
||||
|
||||
list_display = ("album__artist__name", "title", "created_by", "created_at")
|
||||
list_display = ("album__artist__name", "album__name", "title", "created_by", "created_at")
|
||||
search_fields = ("title", "album__artist__name", "album__name")
|
||||
list_filter = ("album__artist__name",)
|
||||
list_filter = ("album__artist__name", "album__name", "created_at")
|
||||
|
||||
|
||||
class TrackInline(admin.TabularInline):
|
||||
|
||||
19
music_storage/music/migrations/0008_alter_track_file.py
Normal file
19
music_storage/music/migrations/0008_alter_track_file.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 6.0 on 2026-01-02 19:24
|
||||
|
||||
import music.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0007_artist_cover_image_alter_album_cover_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='track',
|
||||
name='file',
|
||||
field=models.FileField(upload_to=music.models.track_upload_to),
|
||||
),
|
||||
]
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user