serializers.py 999 Bytes
Newer Older
1

2
3
from rest_framework import serializers

4
from funkwhale_api.activity import serializers as activity_serializers
5
from funkwhale_api.music.serializers import TrackActivitySerializer
6
from funkwhale_api.users.serializers import UserActivitySerializer
7
8
9
10

from . import models


11
12
class TrackFavoriteActivitySerializer(activity_serializers.ModelSerializer):
    type = serializers.SerializerMethodField()
Eliot Berriot's avatar
Eliot Berriot committed
13
14
15
    object = TrackActivitySerializer(source="track")
    actor = UserActivitySerializer(source="user")
    published = serializers.DateTimeField(source="creation_date")
16
17
18

    class Meta:
        model = models.TrackFavorite
Eliot Berriot's avatar
Eliot Berriot committed
19
        fields = ["id", "local_id", "object", "type", "actor", "published"]
20
21
22
23
24

    def get_actor(self, obj):
        return UserActivitySerializer(obj.user).data

    def get_type(self, obj):
Eliot Berriot's avatar
Eliot Berriot committed
25
        return "Like"
26
27


28
29
30
class UserTrackFavoriteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.TrackFavorite
Eliot Berriot's avatar
Eliot Berriot committed
31
        fields = ("id", "track", "creation_date")