Display path names and profile names in capabilities

This commit is contained in:
Gabriel Augendre 2022-10-31 10:31:43 +01:00
parent df8ea865bb
commit 03eabc4bcb

View file

@ -46,6 +46,16 @@ class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
display_name = display_name.replace(text, "") display_name = display_name.replace(text, "")
return display_name.strip().capitalize() 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): class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
path = models.ForeignKey( path = models.ForeignKey(
@ -67,6 +77,12 @@ class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.M
verbose_name = "Capacité" verbose_name = "Capacité"
verbose_name_plural = "Capacités" 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): class RacialCapabilityManager(models.Manager):
def get_by_natural_key(self, name: str, race_id: int): def get_by_natural_key(self, name: str, race_id: int):