Add wikidata ID and year for editions

This commit is contained in:
Lukáš Kucharczyk 2023-02-20 17:13:21 +01:00
parent d2e0bcfb12
commit 850ca382ad
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
5 changed files with 18 additions and 30 deletions

View File

@ -1,5 +1,6 @@
## Unreleased ## Unreleased
* Add wikidata ID and year for editions
* Allow filtering by game, edition, purchase from the session list * Allow filtering by game, edition, purchase from the session list
* Add icons for the above * Add icons for the above

View File

@ -14,7 +14,7 @@ textarea {
#session-table { #session-table {
display: grid; display: grid;
grid-template-columns: 3fr repeat(3, 1fr) 0.5fr 1fr; grid-template-columns: 3fr 2fr repeat(2, 1fr) 0.5fr 1fr;
} }
.purchase-name > span:nth-child(2) { .purchase-name > span:nth-child(2) {

View File

@ -147,7 +147,7 @@ class EditionForm(forms.ModelForm):
class Meta: class Meta:
model = Edition model = Edition
fields = ["game", "name", "sort_name", "platform", "year_released", "wikidata"] fields = ["game", "name", "platform", "year_released", "wikidata"]
class GameForm(forms.ModelForm): class GameForm(forms.ModelForm):

View File

@ -38,13 +38,9 @@ class Edition(models.Model):
game = models.ForeignKey("Game", on_delete=models.CASCADE) game = models.ForeignKey("Game", on_delete=models.CASCADE)
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
sort_name = models.CharField(max_length=255, null=True, blank=True, default=None) platform = models.ForeignKey("Platform", on_delete=models.CASCADE)
platform = models.ForeignKey( year_released = models.IntegerField(default=datetime.today().year)
"Platform", on_delete=models.CASCADE, null=True, blank=True, default=None
)
year_released = models.IntegerField(null=True, blank=True, default=None)
wikidata = models.CharField(max_length=50, null=True, blank=True, default=None) wikidata = models.CharField(max_length=50, null=True, blank=True, default=None)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self): def __str__(self):
return self.sort_name return self.sort_name
@ -134,27 +130,10 @@ class Purchase(models.Model):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
def __str__(self): def __str__(self):
additional_info = [ platform_info = self.platform
self.get_type_display() if self.type != Purchase.GAME else "", if self.platform != self.edition.platform:
f"{self.edition.platform} version on {self.platform}" platform_info = f"{self.edition.platform} version on {self.platform}"
if self.platform != self.edition.platform return f"{self.edition} ({platform_info}, {self.edition.year_released}, {self.get_ownership_type_display()})"
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):
return self.type == self.GAME
def save(self, *args, **kwargs):
if self.type == Purchase.GAME:
self.name = ""
elif self.type != Purchase.GAME and not self.related_purchase:
raise ValidationError(
f"{self.get_type_display()} must have a related purchase."
)
super().save(*args, **kwargs)
class Platform(models.Model): class Platform(models.Model):

View File

@ -55,7 +55,15 @@
</a> </a>
</span> </span>
</div> </div>
<div class="dark:text-white overflow-hidden text-ellipsis whitespace-nowrap"><a class="hover:underline" href="{% url 'list_sessions_by_platform' data.purchase.platform.id %}">{{ data.purchase.platform }}</a></div> <div class="dark:text-white overflow-hidden text-ellipsis whitespace-nowrap">
<a class="hover:underline" href="{% url 'list_sessions_by_platform' data.purchase.platform.id %}">
{% if data.purchase.platform != data.purchase.edition.platform %}
{{data.purchase.edition.platform}} on {{ data.purchase.platform }}
{% else %}
{{ data.purchase.platform }}
{% endif %}
</a>
</div>
<div class="dark:text-slate-400 text-center">{{ data.timestamp_start | date:"d/m/Y H:i" }}</div> <div class="dark:text-slate-400 text-center">{{ data.timestamp_start | date:"d/m/Y H:i" }}</div>
<div class="dark:text-slate-400 text-center"> <div class="dark:text-slate-400 text-center">
{% if data.unfinished %} {% if data.unfinished %}