From 80c86106328cdbb486ea9273531172418b04fd7d Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Thu, 29 Aug 2019 11:45:14 +0200 Subject: [PATCH] =?UTF-8?q?Fixed=20wrong=20ID=C2=A0representation=20in=20g?= =?UTF-8?q?eneric=20relation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/funkwhale_api/common/fields.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/funkwhale_api/common/fields.py b/api/funkwhale_api/common/fields.py index d86283fe5..f1a3e77bd 100644 --- a/api/funkwhale_api/common/fields.py +++ b/api/funkwhale_api/common/fields.py @@ -68,14 +68,16 @@ class GenericRelation(serializers.JSONField): return type = None id = None + id_attr = None for key, choice in self.choices.items(): if isinstance(value, choice["queryset"].model): type = key - id = getattr(value, choice.get("id_attr", "id")) + id_attr = choice.get("id_attr", "id") + id = getattr(value, id_attr) break if type: - return {"type": type, "id": id} + return {"type": type, id_attr: id} def to_internal_value(self, v): v = super().to_internal_value(v)