Skip to content

Commit

Permalink
feat(relations): save with update_fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koeaw committed Apr 8, 2024
1 parent 3ff23cb commit 66e11d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 66e11d4

Please sign in to comment.