Improve price information
All checks were successful
Django CI/CD / test (push) Successful in 1m1s
Django CI/CD / build-and-push (push) Successful in 2m9s

This commit is contained in:
2025-01-30 16:38:13 +01:00
parent 4ec808eeec
commit 6f62889e92
10 changed files with 123 additions and 15 deletions

View File

@ -116,6 +116,8 @@ class Purchase(models.Model):
price_currency = models.CharField(max_length=3, default="USD")
converted_price = models.FloatField(null=True)
converted_currency = models.CharField(max_length=3, null=True)
price_per_game = models.FloatField(null=True)
num_purchases = models.IntegerField(default=0)
ownership_type = models.CharField(
max_length=2, choices=OWNERSHIP_TYPES, default=DIGITAL
)
@ -130,19 +132,16 @@ class Purchase(models.Model):
related_name="related_purchases",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@property
def standardized_price(self):
return (
f"{floatformat(self.converted_price)} {self.converted_currency}"
f"{floatformat(self.converted_price, 0)} {self.converted_currency}"
if self.converted_price
else None
)
@property
def num_purchases(self):
return self.games.count()
@property
def has_one_item(self):
return self.games.count() == 1