Skip to content

Commit fea7117

Browse files
committed
(add) timedelta to int
1 parent fbc3e8a commit fea7117

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tapir/shifts/forms.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
from datetime import timedelta
23

34
from django import forms
@@ -397,6 +398,11 @@ class ConvertShiftExemptionToMembershipPauseForm(forms.Form):
397398
)
398399

399400

401+
class NotificationDurationField(forms.Field):
402+
def prepare_value(self, value: datetime.timedelta) -> int:
403+
return int(value.total_seconds() / 3600)
404+
405+
400406
class ShiftWatchForm(forms.ModelForm):
401407
def clean_notification_timedelta(self):
402408
time = self.data["notification_timedelta"]
@@ -405,6 +411,7 @@ def clean_notification_timedelta(self):
405411
class Meta:
406412
model = ShiftWatch
407413
fields = ["notification_timedelta"]
414+
field_classes = {"notification_timedelta": NotificationDurationField}
408415
widgets = {
409416
"notification_timedelta": forms.NumberInput(
410417
attrs={

0 commit comments

Comments
 (0)