Skip to content

Commit

Permalink
fix: do not expect fields in EntitySerializer
Browse files Browse the repository at this point in the history
We are moving away from expecting fields in our entities, therefore it
makes sense to make the EntitySerializer a bit more flexible. By default
it serializes all the fields of the entity anyway - so we can simply
remove `name`, `start_date` and `end_date` in this case. The `label_set`
is a leftover of the legacy setup with TempEntityClass, we no check for
its existence before adding the field.

Closes: #383
  • Loading branch information
b1rger committed Nov 8, 2023
1 parent f23e9eb commit e4480f3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions apis_core/apis_entities/serializers_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ class TextSerializer(serializers.Serializer):
class EntitySerializer(serializers.Serializer):
id = serializers.IntegerField()
url = serializers.SerializerMethodField(method_name="add_url")
name = serializers.CharField()
start_date = serializers.DateField()
end_date = serializers.DateField()
uris = EntityUriSerializer(source="uri_set", many=True)
labels = LabelSerializer(source="label_set", many=True)
revisions = serializers.SerializerMethodField(method_name="add_revisions")

def add_revisions(self, obj):
Expand Down Expand Up @@ -167,6 +163,8 @@ def __init__(
)
if add_texts:
self.fields["text"] = TextSerializer(many=True)
if hasattr(self.instance, "label_set"):
self.labels = LabelSerializer(source="label_set", many=True)


class RelationEntitySerializer(serializers.Serializer):
Expand Down

0 comments on commit e4480f3

Please sign in to comment.