コード例 #1
0
class AlbumByIdSerializer(serializers.ModelSerializer):
    artist = ArtistSerializer()
    tracks = TrackSerializer(many=True)

    class Meta:
        model = Album
        fields = ['id', 'title', 'price', 'created_at', 'artist', 'tracks']
コード例 #2
0
ファイル: views.py プロジェクト: swkane/MyChoons
 def list(self, request):
     queryset = list(Track.objects.all())
     data = []
     for track in queryset:
         retrieved = GenericProvider(track).retrieve()
         data.append(retrieved)
     serializer = TrackSerializer(data, many=True)
     return Response(serializer.data)
コード例 #3
0
 def broadcast_track_changed(self, track):
     self.publish('player', TrackSerializer(track).data)
     if (track and track.service == Track.SERVICES.deezer
             and track.votes.count() > 0):
         try:
             self.scrobble(track.artist, track.title)
         except (pylast.WSError, IndexError):
             # there is a bug in current version that raises IndexError
             # at some cases
             pass
     self.broadcast_list_changed()
コード例 #4
0
ファイル: endpoints.py プロジェクト: pdyba/hub.rocks
    def create(self, request, *args, **kwargs):
        service_id = self.kwargs['service_id']
        service = self.kwargs['service']

        try:
            self.track = Track.fetch_and_save_track(service, service_id,
                                                    self.establishment)
            Vote.objects.create(track=self.track, token=self.get_token())
        except RequestException:
            return Response(status=status.HTTP_503_SERVICE_UNAVAILABLE)
        except ValueError as e:
            return Response(status=status.HTTP_400_BAD_REQUEST, data=e.message)

        serializer = TrackSerializer(self.track)
        self.broadcast_list_changed()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
コード例 #5
0
ファイル: serializers.py プロジェクト: jihoon6372/ab_dopehotz
class PlayListSerializer(serializers.ModelSerializer):
    track = TrackSerializer(read_only=True)

    class Meta:
        model = PlayList
        fields = ('id', 'track', 'order')
コード例 #6
0
ファイル: views.py プロジェクト: swkane/MyChoons
 def retrieve(self, request, pk=None):
     track = get_object_or_404(Track, id=pk)
     retrieved = GenericProvider(track).retrieve
     serializer = TrackSerializer(retrieved)
     return Response(serializer.data)
コード例 #7
0
ファイル: views.py プロジェクト: swkane/MyChoons
 def create(self, request):
     serializer = TrackSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)