SongCreateSerializer no longer needed.
This commit is contained in:
parent
6dd4fa72ec
commit
253ee3ddd2
2 changed files with 1 additions and 14 deletions
|
@ -34,17 +34,6 @@ class SongSerializer(serializers.ModelSerializer):
|
||||||
'num_played', 'last_played', 'length', 'song_type', 'title')
|
'num_played', 'last_played', 'length', 'song_type', 'title')
|
||||||
|
|
||||||
|
|
||||||
class SongCreateSerializer(SongSerializer):
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
artists_data = validated_data.pop('artists')
|
|
||||||
song = Song.objects.create(**validated_data)
|
|
||||||
for artist_data in artists_data:
|
|
||||||
song.artists.add(artist_data)
|
|
||||||
song.save()
|
|
||||||
return song
|
|
||||||
|
|
||||||
|
|
||||||
class SongRetrieveSerializer(SongSerializer):
|
class SongRetrieveSerializer(SongSerializer):
|
||||||
artists = ArtistFullnameSerializer(many=True)
|
artists = ArtistFullnameSerializer(many=True)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from ..permissions import IsAdminOrReadOnly
|
||||||
from ..serializers.radio import (AlbumSerializer, ArtistSerializer,
|
from ..serializers.radio import (AlbumSerializer, ArtistSerializer,
|
||||||
GameSerializer, SongSerializer,
|
GameSerializer, SongSerializer,
|
||||||
SongArtistsListSerializer,
|
SongArtistsListSerializer,
|
||||||
SongCreateSerializer, SongRetrieveSerializer)
|
SongRetrieveSerializer)
|
||||||
|
|
||||||
|
|
||||||
class AlbumViewSet(viewsets.ModelViewSet):
|
class AlbumViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -40,8 +40,6 @@ class SongViewSet(viewsets.ModelViewSet):
|
||||||
|
|
||||||
(Thanks to https://stackoverflow.com/questions/22616973/)
|
(Thanks to https://stackoverflow.com/questions/22616973/)
|
||||||
'''
|
'''
|
||||||
if self.action == 'create':
|
|
||||||
return SongCreateSerializer
|
|
||||||
if self.action in ['list', 'retrieve']:
|
if self.action in ['list', 'retrieve']:
|
||||||
return SongRetrieveSerializer
|
return SongRetrieveSerializer
|
||||||
return SongSerializer
|
return SongSerializer
|
||||||
|
|
Loading…
Reference in a new issue