Fakultas Ilmu Komputer UI

serializers.py 790 Bytes
Newer Older
Muzaki Azami's avatar
Muzaki Azami committed
1
2
from rest_framework import serializers, fields
from constants.model_choices import PhysicalActivity
3
from authentication.serializers import CustomUserDetailsSerializer
4
from .models import WeeklyReport, WeeklyReportComment
Muzaki Azami's avatar
Muzaki Azami committed
5
6
7
8
9
10
11
12

class WeeklyReportSerializer(serializers.ModelSerializer):
    physical_activity = fields.MultipleChoiceField(
        choices=PhysicalActivity.choices)

    class Meta:
        model = WeeklyReport
        fields = "__all__"
13

14
15
16
17
    def to_representation(self, instance):
        result = super().to_representation(instance)
        result['client'] = CustomUserDetailsSerializer(instance.client).data
        return result
18
19
20
21
22

class WeeklyReportCommentSerializer(serializers.ModelSerializer):
    class Meta:
        model = WeeklyReportComment
        fields = "__all__"