serializers.py 1.2 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 TrackSerializerNested
7
from funkwhale_api.music.serializers import TrackActivitySerializer
8
from funkwhale_api.users.serializers import UserActivitySerializer
9
10
11
12

from . import models


13
14
class TrackFavoriteActivitySerializer(activity_serializers.ModelSerializer):
    type = serializers.SerializerMethodField()
15
    object = TrackActivitySerializer(source='track')
16
17
18
19
20
21
22
    actor = UserActivitySerializer(source='user')
    published = serializers.DateTimeField(source='creation_date')

    class Meta:
        model = models.TrackFavorite
        fields = [
            'id',
23
            'local_id',
24
25
26
27
28
29
30
31
32
33
34
35
36
            'object',
            'type',
            'actor',
            'published'
        ]

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

    def get_type(self, obj):
        return 'Like'


37
38
39
40
41
class UserTrackFavoriteSerializer(serializers.ModelSerializer):
    # track = TrackSerializerNested(read_only=True)
    class Meta:
        model = models.TrackFavorite
        fields = ('id', 'track', 'creation_date')