forked from django-json-api/django-rest-framework-json-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserializers.py
44 lines (31 loc) · 1.08 KB
/
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
39
40
41
42
43
44
from rest_framework_json_api.relations import ResourceRelatedField
from rest_framework_json_api.serializers import ModelSerializer
from tests.models import (
BasicModel,
ForeignKeySource,
ForeignKeyTarget,
ManyToManySource,
ManyToManyTarget,
)
class BasicModelSerializer(ModelSerializer):
class Meta:
fields = ("text",)
model = BasicModel
class ForeignKeySourceSerializer(ModelSerializer):
target = ResourceRelatedField(queryset=ForeignKeyTarget.objects)
class Meta:
model = ForeignKeySource
fields = ("target",)
class ManyToManySourceSerializer(ModelSerializer):
targets = ResourceRelatedField(many=True, queryset=ManyToManyTarget.objects)
class Meta:
model = ManyToManySource
fields = ("targets",)
class ManyToManyTargetSerializer(ModelSerializer):
class Meta:
model = ManyToManyTarget
class ManyToManySourceReadOnlySerializer(ModelSerializer):
targets = ResourceRelatedField(many=True, read_only=True)
class Meta:
model = ManyToManySource
fields = ("targets",)