Skip to content
Snippets Groups Projects
Verified Commit 80c86106 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fixed wrong ID representation in generic relation

parent 6e82780e
No related branches found
No related tags found
No related merge requests found
...@@ -68,14 +68,16 @@ class GenericRelation(serializers.JSONField): ...@@ -68,14 +68,16 @@ class GenericRelation(serializers.JSONField):
return return
type = None type = None
id = None id = None
id_attr = None
for key, choice in self.choices.items(): for key, choice in self.choices.items():
if isinstance(value, choice["queryset"].model): if isinstance(value, choice["queryset"].model):
type = key type = key
id = getattr(value, choice.get("id_attr", "id")) id_attr = choice.get("id_attr", "id")
id = getattr(value, id_attr)
break break
if type: if type:
return {"type": type, "id": id} return {"type": type, id_attr: id}
def to_internal_value(self, v): def to_internal_value(self, v):
v = super().to_internal_value(v) v = super().to_internal_value(v)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment