serializers.py 1.01 KB
Newer Older
1
2
from django.conf import settings

3
4
from rest_framework import serializers

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

from . import models


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

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

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

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


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