Improve purchase __str__

This commit is contained in:
Lukáš Kucharczyk 2023-11-14 19:55:56 +01:00
parent d280fa3798
commit 410f20acea
2 changed files with 10 additions and 4 deletions

View File

@ -2,6 +2,7 @@
## Improved ## Improved
* Disallow choosing non-game purchase as related purchase * Disallow choosing non-game purchase as related purchase
* Improve display of purchases
## 1.5.0 / 2023-11-14 19:27+01:00 ## 1.5.0 / 2023-11-14 19:27+01:00

View File

@ -128,10 +128,15 @@ class Purchase(models.Model):
) )
def __str__(self): def __str__(self):
platform_info = self.platform additional_info = [
if self.platform != self.edition.platform: self.get_type_display() if self.type != Purchase.GAME else "",
platform_info = f"{self.edition.platform} version on {self.platform}" f"{self.edition.platform} version on {self.platform}"
return f"{self.edition} ({platform_info}, {self.edition.year_released}, {self.get_ownership_type_display()})" 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): def is_game(self):
return self.type == self.GAME return self.type == self.GAME