From cce810e8cf5c9cd87a558e580f54c27bdc6ba887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 14 Nov 2023 19:55:56 +0100 Subject: [PATCH] Improve purchase __str__ --- CHANGELOG.md | 1 + games/models.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d15c7..a7202df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Improved * Disallow choosing non-game purchase as related purchase +* Improve display of purchases ## 1.5.0 / 2023-11-14 19:27+01:00 diff --git a/games/models.py b/games/models.py index 461f106..223c3f6 100644 --- a/games/models.py +++ b/games/models.py @@ -128,10 +128,15 @@ class Purchase(models.Model): ) def __str__(self): - platform_info = self.platform - if self.platform != self.edition.platform: - platform_info = f"{self.edition.platform} version on {self.platform}" - return f"{self.edition} ({platform_info}, {self.edition.year_released}, {self.get_ownership_type_display()})" + additional_info = [ + self.get_type_display() if self.type != Purchase.GAME else "", + f"{self.edition.platform} version on {self.platform}" + if self.platform != self.edition.platform + else self.platform, + self.edition.year_released, + self.get_ownership_type_display(), + ] + return f"{self.edition} ({', '.join(filter(None, map(str, additional_info)))})" def is_game(self): return self.type == self.GAME