From 4086c078bd345836e6e5beebc06e0bf86f8cd290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 20 Feb 2023 17:15:21 +0100 Subject: [PATCH] Improve display of editions on purchase form --- games/forms.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/games/forms.py b/games/forms.py index 1ac0134..6e1a380 100644 --- a/games/forms.py +++ b/games/forms.py @@ -20,8 +20,13 @@ class SessionForm(forms.ModelForm): ] +class EditionChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj) -> str: + return f"{obj.name} ({obj.platform}, {obj.year_released})" + + class PurchaseForm(forms.ModelForm): - edition = forms.ModelChoiceField(queryset=Edition.objects.order_by("name")) + edition = EditionChoiceField(queryset=Edition.objects.order_by("name")) platform = forms.ModelChoiceField(queryset=Platform.objects.order_by("name")) class Meta: