Allow setting game to Finished when creating PlayEvent
This commit is contained in:
parent
ad0641f95b
commit
bc972150e4
@ -227,6 +227,12 @@ class PlayEventForm(forms.ModelForm):
|
|||||||
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mark_as_finished = forms.BooleanField(
|
||||||
|
required=False,
|
||||||
|
initial={"mark_as_finished": True},
|
||||||
|
label="Set game status to Finished",
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PlayEvent
|
model = PlayEvent
|
||||||
fields = [
|
fields = [
|
||||||
@ -234,11 +240,21 @@ class PlayEventForm(forms.ModelForm):
|
|||||||
"started",
|
"started",
|
||||||
"ended",
|
"ended",
|
||||||
"note",
|
"note",
|
||||||
|
"mark_as_finished"
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
"started": custom_date_widget,
|
"started": custom_date_widget,
|
||||||
"ended": custom_date_widget,
|
"ended": custom_date_widget,
|
||||||
}
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
with transaction.atomic():
|
||||||
|
session = super().save(commit=False)
|
||||||
|
if self.cleaned_data.get("mark_as_finished"):
|
||||||
|
game_instance = session.game
|
||||||
|
game_instance.status = "f"
|
||||||
|
game_instance.save()
|
||||||
|
session.save()
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
class GameStatusChangeForm(forms.ModelForm):
|
class GameStatusChangeForm(forms.ModelForm):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user