From 66e11d4130329b136d9988d116e4463d7de11a8b Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 8 Apr 2024 09:16:17 +0200 Subject: [PATCH] feat(relations): save with update_fields When Property's save method is called with update_fields to update any of the name fields, make sure both name fields are considered when saving. --- 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 6bbc93621..08be124ee 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -85,6 +85,12 @@ def save(self, *args, **kwargs): self.name_reverse = unicodedata.normalize("NFC", self.name_reverse) if self.name_reverse == "" or self.name_reverse is None: self.name_reverse = self.name_forward + " [REVERSE]" + + if "update_fields" in kwargs and ( + include_fields := {"name_forward", "name_reverse"} + ).intersection(update_fields := kwargs.get("update_fields")): + kwargs["update_fields"] = set(update_fields) | include_fields + super(Property, self).save(*args, **kwargs) return self