Fix add/edit session screen
This commit is contained in:
parent
aba9bc994d
commit
2d7342c0d5
@ -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"}),
|
||||
)
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user