Fixed wrong ID representation in generic relation

environments/review-docs-rate-jr6phc/deployments/2479
Eliot Berriot 2019-08-29 11:45:14 +02:00
rodzic 6e82780e0d
commit 80c8610632
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
1 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -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)