serializers.py
2.25 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from common.models import Institute, PyrosUser, ScienceTheme, ScientificProgram, Sequence, Plan, Album
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
user_level = serializers.StringRelatedField(many=True)
class Meta:
model = PyrosUser
fields = ['url', 'username', 'email', 'institute',
"user_level"]
depth = 1
class InstituteSerializer(serializers.ModelSerializer):
class Meta:
model = Institute
fields = ["name"]
class ScienceThemeSerializer(serializers.ModelSerializer):
class Meta:
model = ScienceTheme
fields = ["name"]
class ScientificProgramSerializer(serializers.ModelSerializer):
sp_pi = UserSerializer(read_only=True)
institute = InstituteSerializer(read_only=True)
science_theme = ScienceThemeSerializer(read_only=True)
class Meta:
model = ScientificProgram
fields = ["name", "institute", "sp_pi", "description_short",
"description_long", "science_theme"]
#fields = "__all__"
class SequenceSerializer(serializers.ModelSerializer):
pyros_user = UserSerializer(read_only=True)
class Meta:
model = Sequence
fields = "__all__"
class AlbumSerializer(serializers.ModelSerializer):
sequence = SequenceSerializer(read_only=True)
class Meta:
model = Album
fields = "__all__"
class PlanSerializer(serializers.ModelSerializer):
album = AlbumSerializer(read_only=True)
class Meta:
model = Plan
fields = "__all__"
class SimplePlanSerializer(serializers.ModelSerializer):
class Meta:
model = Plan
exclude = ["album"]
class SimpleAlbumSerializer(serializers.ModelSerializer):
plans = SimplePlanSerializer(read_only=True, many=True)
class Meta:
model = Album
fields = ["name", "desc", "plans"]
class FullSequenceSerializer(serializers.ModelSerializer):
pyros_user = UserSerializer(read_only=True)
# here albums is the relationmodel with many to many realtion so we have to set many to True
albums = SimpleAlbumSerializer(read_only=True, many=True)
class Meta:
model = Sequence
fields = "__all__"
extra_fields = ["pyros_user", "albums"]