From 03eabc4bcb1fe09d7c0e57b88f356435b4b548bf Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 31 Oct 2022 10:31:43 +0100 Subject: [PATCH] Display path names and profile names in capabilities --- src/character/models/capabilities.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/character/models/capabilities.py b/src/character/models/capabilities.py index d6060a9..883c3b4 100644 --- a/src/character/models/capabilities.py +++ b/src/character/models/capabilities.py @@ -46,6 +46,16 @@ class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): display_name = display_name.replace(text, "") return display_name.strip().capitalize() + @property + def related_to(self) -> UniquelyNamedModel | None: + category = Path.Category(self.category) + if category == Path.Category.PROFILE: + return self.profile + elif category == Path.Category.RACE: + return self.race + else: + return None + class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): path = models.ForeignKey( @@ -67,6 +77,12 @@ class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.M verbose_name = "Capacité" verbose_name_plural = "Capacités" + def __str__(self): + description = f"{self.name} - {self.path.name}" + if self.path.related_to: + description += f" ({self.path.related_to.name})" + return description + class RacialCapabilityManager(models.Manager): def get_by_natural_key(self, name: str, race_id: int):