From 7330a9f8f5d0867e9d073393578aeae725116e33 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 22 Apr 2026 09:18:41 -0400 Subject: [PATCH] feat(models): add Tag.display_name @property Single source of truth for human-readable tag rendering. Falls back to tag.name when no fandom is attached, preserving pre-migration data shapes. Co-Authored-By: Claude Opus 4.7 --- app/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models.py b/app/models.py index 88117bc..889479d 100644 --- a/app/models.py +++ b/app/models.py @@ -54,6 +54,19 @@ class Tag(db.Model): passive_deletes=True, ) + @property + def display_name(self) -> str: + """Human-readable rendering of this tag. + + After the bare-name refactor, `name` holds the display text directly for + every kind except character+fandom, which gets the '(Fandom)' suffix + appended here. Pre-migration data (with 'kind:' prefix in name) still + renders sanely via the else branch — callers see the raw stored string. + """ + if self.kind == 'character' and self.fandom is not None: + return f"{self.name} ({self.fandom.name})" + return self.name + class ArchiveRecord(db.Model): """ Tracks archives we've processed so we can skip re-importing the same large file.