From 846f69979aad79c54c8050bc47c008912d19de2e Mon Sep 17 00:00:00 2001 From: Neraste Date: Mon, 25 Apr 2022 11:40:14 +0900 Subject: [PATCH] Reverse playlist played entries order and add was_played to playlist serializer --- dakara_server/playlist/serializers.py | 3 ++- dakara_server/playlist/tests/test_playlist_played.py | 4 ++-- dakara_server/playlist/views.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dakara_server/playlist/serializers.py b/dakara_server/playlist/serializers.py index 247907a1..1601fa76 100644 --- a/dakara_server/playlist/serializers.py +++ b/dakara_server/playlist/serializers.py @@ -41,8 +41,9 @@ class Meta: "song_id", "use_instrumental", "date_play", + "was_played", ) - read_only_fields = ("date_created", "date_play") + read_only_fields = ("date_created", "date_play", "was_played") def validate(self, data): if data.get("use_instrumental") and not data["song"].has_instrumental: diff --git a/dakara_server/playlist/tests/test_playlist_played.py b/dakara_server/playlist/tests/test_playlist_played.py index 5c367a5f..3455e380 100644 --- a/dakara_server/playlist/tests/test_playlist_played.py +++ b/dakara_server/playlist/tests/test_playlist_played.py @@ -23,8 +23,8 @@ def test_get_playlist_played_list(self): self.assertEqual(len(response.data["results"]), 2) # Playlist entries are in order of creation - self.check_playlist_played_entry_json(response.data["results"][0], self.pe3) - self.check_playlist_played_entry_json(response.data["results"][1], self.pe4) + self.check_playlist_played_entry_json(response.data["results"][0], self.pe4) + self.check_playlist_played_entry_json(response.data["results"][1], self.pe3) def test_get_playlist_played_list_forbidden(self): """Test to verify playlist entries played list forbidden when not logged in.""" diff --git a/dakara_server/playlist/views.py b/dakara_server/playlist/views.py index e9ee9065..b1c905c0 100644 --- a/dakara_server/playlist/views.py +++ b/dakara_server/playlist/views.py @@ -158,7 +158,7 @@ class PlaylistPlayedListView(drf_generics.ListAPIView): """List of played entries.""" serializer_class = serializers.PlaylistEntrySerializer - queryset = models.PlaylistEntry.objects.get_played() + queryset = models.PlaylistEntry.objects.get_played().reverse() class PlayerCommandView(drf_generics.UpdateAPIView):