Fix add/edit session screen
All checks were successful
Django CI/CD / test (push) Successful in 1m5s
Django CI/CD / build-and-push (push) Successful in 2m14s

This commit is contained in:
Lukáš Kucharczyk 2025-02-08 17:54:03 +01:00
parent aba9bc994d
commit 2d7342c0d5
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
2 changed files with 11 additions and 5 deletions

View File

@ -11,13 +11,18 @@ custom_datetime_widget = forms.DateTimeInput(
autofocus_input_widget = forms.TextInput(attrs={"autofocus": "autofocus"})
class GameChoiceField(forms.ModelMultipleChoiceField):
class MultipleGameChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj) -> str:
return f"{obj.sort_name} ({obj.platform}, {obj.year_released})"
class SingleGameChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj) -> str:
return f"{obj.sort_name} ({obj.platform}, {obj.year_released})"
class SessionForm(forms.ModelForm):
game = GameChoiceField(
game = SingleGameChoiceField(
queryset=Game.objects.order_by("sort_name"),
widget=forms.Select(attrs={"autofocus": "autofocus"}),
)
@ -84,7 +89,7 @@ class PurchaseForm(forms.ModelForm):
}
)
games = GameChoiceField(
games = MultipleGameChoiceField(
queryset=Game.objects.order_by("sort_name"),
widget=IncludePlatformSelect(attrs={"autoselect": "autoselect"}),
)

View File

@ -215,7 +215,8 @@ def add_session(request: HttpRequest, game_id: int = 0) -> HttpResponse:
form = SessionForm(initial=initial)
context["title"] = "Add New Session"
context["script_name"] = "add_session.js"
# TODO: re-add custom buttons #91
# context["script_name"] = "add_session.js"
context["form"] = form
return render(request, "add.html", context)
@ -231,7 +232,7 @@ def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
return redirect("list_sessions")
context["title"] = "Edit Session"
context["form"] = form
return render(request, "add_session.html", context)
return render(request, "add.html", context)
def clone_session_by_id(session_id: int) -> Session: