Commit edd7fb42 authored by Auri's avatar Auri
Browse files

Credit: begin work on TrackCredit

parent bbc36201
Pipeline #2817 failed with stages
in 37 seconds
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
def populate_track_credit(apps, schema_editor):
from funkwhale_api.music.models import Credit
TrackCredit = apps.get_model("music", "TrackCredit")
Track = apps.get_model("music", "Track")
for tk in Track.objects.all():
tc = TrackCredit()
tc.artist = tk.artist
tc.track = tk
tc.credit = Credit.MAIN
tc.save()
def rewind(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
("music", "0036_track_disc_number"),
]
operations = [
migrations.CreateModel(
name="TrackCredit",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("affiliation", models.CharField(choices=[("main", "Main"), ("featured", "Featured"), ("composer", "Composer"), ("conductor", "Conductor"), ("compiler", "Compiler"), ("remixer", "Remixer"), ("producer", "Producer")], default="main", max_length=30)),
("artist", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="credits", to="music.Artist")),
("track", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="credits", to="music.Track")),
],
),
migrations.AlterUniqueTogether(
name='trackcredit',
unique_together={('artist', 'track', 'affiliation')},
),
migrations.RunPython(populate_track_credit, rewind),
]
......@@ -621,6 +621,37 @@ class UploadQuerySet(models.QuerySet):
return self.exclude(audio_file=None).exclude(audio_file="")
class Credit:
MAIN = "main"
FEATURED = "featured"
COMPOSER = "composer"
CONDUCTOR = "conductor"
COMPILER = "compiler"
REMIXER = "remixer"
PRODUCER = "producer"
_CHOICES = (
(MAIN, "Main"),
(FEATURED, "Featured"),
(COMPOSER, "Composer"),
(CONDUCTOR, "Conductor"),
(COMPILER, "Compiler"),
(REMIXER, "Remixer"),
(PRODUCER, "Producer"),
)
class TrackCredit(models.Model):
artist = models.ForeignKey(Artist, related_name="credits", on_delete=models.CASCADE)
track = models.ForeignKey(Track, related_name="credits", on_delete=models.CASCADE)
affiliation = models.CharField(
max_length=30, default=Credit.MAIN, choices=Credit._CHOICES
)
class Meta:
unique_together = (('artist', 'track', 'affiliation'),)
TRACK_FILE_IMPORT_STATUS_CHOICES = (
("pending", "Pending"),
("finished", "Finished"),
......
......@@ -77,8 +77,17 @@ class ArtistSimpleSerializer(serializers.ModelSerializer):
fields = ("id", "mbid", "name", "creation_date")
class ArtistCreditSerializer(serializers.ModelSerializer):
artist = ArtistSimpleSerializer()
class Meta:
model = models.TrackCredit
fields = ("artist", "affiliation")
class AlbumTrackSerializer(serializers.ModelSerializer):
artist = ArtistSimpleSerializer(read_only=True)
credits = ArtistCreditSerializer(many=True, read_only=True)
uploads = serializers.SerializerMethodField()
listen_url = serializers.SerializerMethodField()
duration = serializers.SerializerMethodField()
......@@ -91,6 +100,7 @@ class AlbumTrackSerializer(serializers.ModelSerializer):
"title",
"album",
"artist",
"credits",
"creation_date",
"position",
"disc_number",
......@@ -181,6 +191,7 @@ class TrackUploadSerializer(serializers.ModelSerializer):
class TrackSerializer(serializers.ModelSerializer):
artist = ArtistSimpleSerializer(read_only=True)
credits = ArtistCreditSerializer(many=True, read_only=True)
album = TrackAlbumSerializer(read_only=True)
lyrics = serializers.SerializerMethodField()
uploads = serializers.SerializerMethodField()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment