Skip to content

Commit

Permalink
fix: dynamically create serializers for relations
Browse files Browse the repository at this point in the history
  • Loading branch information
sennierer committed Nov 27, 2024
1 parent dc1ef5f commit 2faa6c0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apis_ontology/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
from rest_framework.renderers import serializers
from rdflib import Graph, Literal, URIRef, Namespace
from rdflib.namespace import RDF, RDFS, XSD
from apis_core.generic.serializers import GenericHyperlinkedModelSerializer
from apis_core.relations.utils import relation_content_types

# Dynamically create and add serializer classes to this module
for ct in relation_content_types():
cls = ct.model_class()
if cls.__name__ == "Relation":
continue
serializer_class = type(
f"{cls.__name__}Serializer",
(GenericHyperlinkedModelSerializer,),
{
"__module__": __name__,
"Meta": type("Meta", (), {"model": cls, "fields": "__all__"}),
},
)
# Add the new serializer class to the module globals
globals()[f"{cls.__name__}Serializer"] = serializer_class


class PersonCidocSerializer(serializers.BaseSerializer):
Expand Down

0 comments on commit 2faa6c0

Please sign in to comment.