serializers.py 1.09 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()
14
    object = TrackActivitySerializer(source='track')
15
16
17
18
19
20
21
    actor = UserActivitySerializer(source='user')
    published = serializers.DateTimeField(source='creation_date')

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

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

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


36
37
38
39
class UserTrackFavoriteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.TrackFavorite
        fields = ('id', 'track', 'creation_date')