24 lines
809 B
Python
24 lines
809 B
Python
from rest_framework import serializers
|
|
from .models import Song, FavoriteSong
|
|
|
|
class SongSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Song
|
|
fields = ('id', 'unique_id', 'azura_id', 'title', 'artist', 'album', 'genre', 'art')
|
|
|
|
class FavoriteSongSerializer(serializers.ModelSerializer):
|
|
song = serializers.SerializerMethodField()
|
|
class Meta:
|
|
model = FavoriteSong
|
|
fields = ('id', 'song', 'user')
|
|
|
|
def get_song(self, favorite_song):
|
|
song = Song.objects.get(id=favorite_song.song_id)
|
|
return SongSerializer(song, many=True).data
|
|
""" def to_representation(self, instance):
|
|
rep = super().to_representation(instance)
|
|
rep["song"] = SongSerializer(
|
|
instance.song).data
|
|
return rep """
|
|
|