From b0be7b5887a875726e188fbfc9b852a377cf79c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 9 Nov 2023 15:41:46 +0100 Subject: [PATCH] Fix sort names getting mangled --- games/models.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/games/models.py b/games/models.py index 7f2ce1b..97462c1 100644 --- a/games/models.py +++ b/games/models.py @@ -18,20 +18,17 @@ class Game(models.Model): return self.name def save(self, *args, **kwargs): - # Logic to create sort_name from name def get_sort_name(name): articles = ["a", "an", "the"] name_parts = name.split() first_word = name_parts[0].lower() if first_word in articles: - # Move the first word to the end - name_parts.append(name_parts.pop(0)) - return ", ".join(name_parts).capitalize() + return f"{' '.join(name_parts[1:])}, {name_parts[0]}" else: - return name.capitalize() + return name self.sort_name = get_sort_name(self.name) - super().save(*args, **kwargs) # Call the "real" save() method. + super().save(*args, **kwargs) class Edition(models.Model): @@ -51,20 +48,17 @@ class Edition(models.Model): return self.sort_name def save(self, *args, **kwargs): - # Logic to create sort_name from name def get_sort_name(name): articles = ["a", "an", "the"] name_parts = name.split() first_word = name_parts[0].lower() if first_word in articles: - # Move the first word to the end - name_parts.append(name_parts.pop(0)) - return ", ".join(name_parts).capitalize() + return f"{' '.join(name_parts[1:])}, {name_parts[0]}" else: - return name.capitalize() + return name self.sort_name = get_sort_name(self.name) - super().save(*args, **kwargs) # Call the "real" save() method. + super().save(*args, **kwargs) class PurchaseQueryset(models.QuerySet):