Compare commits

..

No commits in common. "b0be7b5887a875726e188fbfc9b852a377cf79c2" and "a879360ebd281514867bf3f10c6e322cdedd0730" have entirely different histories.

4 changed files with 13 additions and 14 deletions

View File

@ -30,7 +30,7 @@
* added a new sort_name field that gets automatically created
* automatically fill certain values in forms:
* new game: name and sort name after typing
* new edition: name, sort name, and year when selecting game
* new edition: name and sort name when selecting game
* new purchase: platform when selecting edition
## 1.3.0 / 2023-11-05 15:09+01:00

View File

@ -80,7 +80,6 @@ class IncludeNameSelect(forms.Select):
option = super().create_option(name, value, *args, **kwargs)
if value:
option["attrs"]["data-name"] = value.instance.name
option["attrs"]["data-year"] = value.instance.year_released
return option

View File

@ -18,17 +18,20 @@ 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:
return f"{' '.join(name_parts[1:])}, {name_parts[0]}"
# Move the first word to the end
name_parts.append(name_parts.pop(0))
return ", ".join(name_parts).capitalize()
else:
return name
return name.capitalize()
self.sort_name = get_sort_name(self.name)
super().save(*args, **kwargs)
super().save(*args, **kwargs) # Call the "real" save() method.
class Edition(models.Model):
@ -48,17 +51,20 @@ 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:
return f"{' '.join(name_parts[1:])}, {name_parts[0]}"
# Move the first word to the end
name_parts.append(name_parts.pop(0))
return ", ".join(name_parts).capitalize()
else:
return name
return name.capitalize()
self.sort_name = get_sort_name(self.name)
super().save(*args, **kwargs)
super().save(*args, **kwargs) # Call the "real" save() method.
class PurchaseQueryset(models.QuerySet):

View File

@ -13,12 +13,6 @@ let syncData = [
"target": "#id_sort_name",
"target_value": "value"
},
{
"source": "#id_game",
"source_value": "dataset.year",
"target": "#id_year_released",
"target_value": "value"
},
]
syncSelectInputUntilChanged(syncData, "form");