From f97f0f0aedbb088d2cb2f4edf9d8a03e0851e8bc Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 29 Aug 2024 11:14:03 -0500 Subject: [PATCH] fix: serialize lineage data as json --- platform_plugin_aspects/sinks/serializers.py | 38 +++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/platform_plugin_aspects/sinks/serializers.py b/platform_plugin_aspects/sinks/serializers.py index a8596d9..ca04686 100644 --- a/platform_plugin_aspects/sinks/serializers.py +++ b/platform_plugin_aspects/sinks/serializers.py @@ -211,7 +211,7 @@ def get_course_key(self, obj): class TagSerializer(BaseSinkSerializer, serializers.ModelSerializer): """Serializer for the Tag model.""" - lineage = serializers.CharField(source="get_lineage") + lineage = serializers.SerializerMethodField() class Meta: """Meta class for the TagSerializer.""" @@ -228,26 +228,14 @@ class Meta: "time_last_dumped", ] - -class TaxonomySerializer(BaseSinkSerializer, serializers.ModelSerializer): - """Serializer for the Taxonomy model.""" - - class Meta: - """Meta class for the TaxonomySerializer.""" - - model = get_model("taxonomy") - fields = [ - "id", - "name", - "dump_id", - "time_last_dumped", - ] + def get_lineage(self, instance): + return json.dumps(instance.get_lineage()) class ObjectTagSerializer(BaseSinkSerializer, serializers.ModelSerializer): """Serializer for the ObjectTag model.""" - lineage = serializers.CharField(source="get_lineage") + lineage = serializers.SerializerMethodField() class Meta: """Meta class for the ObjectTagSerializer""" @@ -264,3 +252,21 @@ class Meta: "dump_id", "time_last_dumped", ] + + def get_lineage(self, instance): + return json.dumps(instance.get_lineage()) + + +class TaxonomySerializer(BaseSinkSerializer, serializers.ModelSerializer): + """Serializer for the Taxonomy model.""" + + class Meta: + """Meta class for the TaxonomySerializer.""" + + model = get_model("taxonomy") + fields = [ + "id", + "name", + "dump_id", + "time_last_dumped", + ]