Skip to content

Commit

Permalink
feat(relations): save with update_fields
Browse files Browse the repository at this point in the history
If only one name field is passed to Property's
save method with update_fields, make sure both
name fields are considered for saving.
  • Loading branch information
koeaw committed Apr 8, 2024
1 parent 3ff23cb commit d1a04fe
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 d1a04fe

Please sign in to comment.