From a9e52c52e01ff0acb8ed1f4835a741b2bb1604e0 Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 8 Apr 2024 09:16:17 +0200 Subject: [PATCH] fix(relations): save with update_fields When Property's save method is called with update_fields to update name_forward, make sure name_reverse is saved as well. --- apis_core/apis_relations/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index fa1aa1a98..2f0bbb5f0 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -87,6 +87,12 @@ def save(self, *args, **kwargs): self.name_forward = unicodedata.normalize("NFC", str(self.name_forward)) self.name_reverse = unicodedata.normalize("NFC", str(self.name_reverse)) + if (update_fields := kwargs.get("update_fields")) is not None: + if "name_forward" in update_fields and "name_reverse" not in update_fields: + modified_update_fields = set(update_fields) + modified_update_fields.add("name_reverse") + kwargs["update_fields"] = modified_update_fields + super(Property, self).save(*args, **kwargs) return self