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"}),
|
||||
)
|
||||
|
||||
mark_as_finished = forms.BooleanField(
|
||||
required=False,
|
||||
initial={"mark_as_finished": True},
|
||||
label="Set game status to Finished",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = PlayEvent
|
||||
fields = [
|
||||
@ -234,11 +240,21 @@ class PlayEventForm(forms.ModelForm):
|
||||
"started",
|
||||
"ended",
|
||||
"note",
|
||||
"mark_as_finished"
|
||||
]
|
||||
widgets = {
|
||||
"started": 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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user