Coverage for apis_core/relations/serializers.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1from drf_spectacular.utils import extend_schema_field 

2from rest_framework.serializers import SerializerMethodField 

3 

4from apis_core.generic.serializers import SimpleObjectSerializer, serializer_factory 

5 

6 

7class RelationSerializer(SimpleObjectSerializer): 

8 subj = SerializerMethodField() 

9 obj = SerializerMethodField() 

10 

11 class Meta: 

12 fields = SimpleObjectSerializer.Meta.fields + ["subj", "obj"] 

13 

14 @extend_schema_field(SimpleObjectSerializer()) 

15 def get_subj(self, obj): 

16 serializer = serializer_factory(type(obj.subj), SimpleObjectSerializer) 

17 return serializer(obj.subj, context={"request": self.context["request"]}).data 

18 

19 @extend_schema_field(SimpleObjectSerializer()) 

20 def get_obj(self, obj): 

21 serializer = serializer_factory(type(obj.obj), SimpleObjectSerializer) 

22 return serializer(obj.obj, context={"request": self.context["request"]}).data