feat: human readable duration
This commit is contained in:
@@ -72,6 +72,17 @@ class Booking(models.Model):
|
|||||||
return round(diff.total_seconds() / 60)
|
return round(diff.total_seconds() / 60)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def human_duration(self) -> 'str|None':
|
||||||
|
total = self.duration
|
||||||
|
if total is None:
|
||||||
|
return None
|
||||||
|
if total > 1440:
|
||||||
|
return f'> {total // 1440}T'
|
||||||
|
min = total % 60
|
||||||
|
hour = (total - min) // 60
|
||||||
|
return f'{hour}:{min:02d}'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def calculated_price(self):
|
def calculated_price(self):
|
||||||
traits = self.user.traits_at_date(self.begin_time).values_list('trait')
|
traits = self.user.traits_at_date(self.begin_time).values_list('trait')
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class BookingOptions(ViewOptions[Booking], LoginRequired):
|
|||||||
'delete': 'booking:delete'
|
'delete': 'booking:delete'
|
||||||
}
|
}
|
||||||
list_filter = {'user': 'user__pk'}
|
list_filter = {'user': 'user__pk'}
|
||||||
list_columns = ['begin_time', 'end_time', 'duration', 'user', 'type']
|
list_columns = ['begin_time', 'end_time', 'human_duration', 'user', 'type']
|
||||||
list_render = {
|
list_render = {
|
||||||
'begin_time': {
|
'begin_time': {
|
||||||
'date_format': 'D. d.m.y, H:i',
|
'date_format': 'D. d.m.y, H:i',
|
||||||
@@ -31,7 +31,7 @@ class BookingOptions(ViewOptions[Booking], LoginRequired):
|
|||||||
'date_format': 'H:i',
|
'date_format': 'H:i',
|
||||||
'width': '4rem',
|
'width': '4rem',
|
||||||
},
|
},
|
||||||
'duration': {
|
'human_duration': {
|
||||||
'verbose_name': 'Dauer',
|
'verbose_name': 'Dauer',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class PersonDetailView(PersonOptions, ModelDetailView):
|
|||||||
'update': 'booking:update',
|
'update': 'booking:update',
|
||||||
'delete': 'booking:delete'
|
'delete': 'booking:delete'
|
||||||
},
|
},
|
||||||
'columns': ['begin_time', 'end_time', 'duration', 'type'],
|
'columns': ['begin_time', 'end_time', 'human_duration', 'type'],
|
||||||
'render': {
|
'render': {
|
||||||
'begin_time': {
|
'begin_time': {
|
||||||
'date_format': 'D. d.m.y, H:i',
|
'date_format': 'D. d.m.y, H:i',
|
||||||
@@ -97,7 +97,7 @@ class PersonDetailView(PersonOptions, ModelDetailView):
|
|||||||
'date_format': 'H:i',
|
'date_format': 'H:i',
|
||||||
'width': '4rem',
|
'width': '4rem',
|
||||||
},
|
},
|
||||||
'duration': {
|
'human_duration': {
|
||||||
'verbose_name': 'Dauer',
|
'verbose_name': 'Dauer',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user