From 9992d9c9bdf5bdddc5bc56d9530860a13c3648e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 16 Oct 2024 18:06:40 +0200 Subject: [PATCH] set edition platform to unspecified if none --- games/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/games/models.py b/games/models.py index 143f9bd..f016585 100644 --- a/games/models.py +++ b/games/models.py @@ -38,6 +38,12 @@ class Platform(models.Model): super().save(*args, **kwargs) +def get_sentinel_platform(): + return Platform.objects.get_or_create( + name="Unspecified", icon="unspecified", group="Unspecified" + )[0] + + class Edition(models.Model): class Meta: unique_together = [["name", "platform", "year_released"]] @@ -55,6 +61,11 @@ class Edition(models.Model): def __str__(self): return self.sort_name + def save(self, *args, **kwargs): + if self.platform is None: + self.platform = get_sentinel_platform() + super().save(*args, **kwargs) + class PurchaseQueryset(models.QuerySet): def refunded(self):