Coverage for apis_core/relations/serializers.py: 0%
18 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-20 09:24 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-20 09:24 +0000
1from drf_spectacular.utils import extend_schema_field
2from rest_framework.serializers import SerializerMethodField
4from apis_core.generic.serializers import SimpleObjectSerializer, serializer_factory
7class RelationSerializer(SimpleObjectSerializer):
8 subj = SerializerMethodField()
9 obj = SerializerMethodField()
11 class Meta:
12 fields = SimpleObjectSerializer.Meta.fields + ["subj", "obj"]
14 @extend_schema_field(SimpleObjectSerializer())
15 def get_subj(self, obj):
16 if obj.subj:
17 serializer = serializer_factory(type(obj.subj), SimpleObjectSerializer)
18 return serializer(
19 obj.subj, context={"request": self.context["request"]}
20 ).data
22 @extend_schema_field(SimpleObjectSerializer())
23 def get_obj(self, obj):
24 if obj.obj:
25 serializer = serializer_factory(type(obj.obj), SimpleObjectSerializer)
26 return serializer(
27 obj.obj, context={"request": self.context["request"]}
28 ).data