forked from wafflestudio/seminar-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serializers.py
38 lines (30 loc) · 888 Bytes
/
serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from rest_framework import serializers
from survey.models import OperatingSystem, SurveyResult
class SurveyResultSerializer(serializers.ModelSerializer):
os = serializers.SerializerMethodField(read_only=True)
class Meta:
model = SurveyResult
fields = (
'id',
'os',
'python',
'rdb',
'programming',
'major',
'grade',
'backend_reason',
'waffle_reason',
'say_something',
'timestamp',
)
def get_os(self, survey):
return OperatingSystemSerializer(survey.os, context=self.context).data
class OperatingSystemSerializer(serializers.ModelSerializer):
class Meta:
model = OperatingSystem
fields = (
'id',
'name',
'description',
'price',
)