fix(game): show game name in dropdown labels (#43)

search_label built its label from sort_name, an optional sort key that
is blank for most games, so the Game and Related-game dropdowns in the
add-purchase form (and the session form and search API, which share the
property) showed a blank/"None" label. Use name, which is required.

Also route search_label and Purchase.full_name through label_with_details
so a missing year_released drops out of the parenthetical instead of
rendering a literal "None". (platform is never None at display time -
Game.save() substitutes the "Unspecified" sentinel.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-21 19:48:42 +02:00
parent 49601bb4fc
commit 1c0c067377
3 changed files with 43 additions and 11 deletions
+8 -11
View File
@@ -12,6 +12,7 @@ from django.template.defaultfilters import floatformat, pluralize, slugify
from django.utils import timezone
from common.time import format_duration
from common.utils import label_with_details
logger = logging.getLogger("games")
@@ -67,7 +68,7 @@ class Game(models.Model):
@property
def search_label(self) -> str:
return f"{self.sort_name} ({self.platform}, {self.year_released})"
return label_with_details(self.name, self.platform, self.year_released)
def finished(self):
return (
@@ -234,16 +235,12 @@ class Purchase(models.Model):
@property
def full_name(self):
additional_info = [
str(item)
for item in [
f"{self.num_purchases} game{pluralize(self.num_purchases)}",
self.date_purchased,
self.standardized_price,
]
if item
]
return f"{self.standardized_name} ({', '.join(additional_info)})"
return label_with_details(
self.standardized_name,
f"{self.num_purchases} game{pluralize(self.num_purchases)}",
self.date_purchased,
self.standardized_price,
)
def is_game(self):
return self.type == self.GAME