fix: locale datetime for booking

This commit is contained in:
relikd
2023-06-02 17:05:17 +02:00
parent e0a0c58948
commit 4cac963a5e

View File

@@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.forms.utils import to_current_timezone
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
@@ -31,11 +32,13 @@ class Booking(models.Model):
return reverse('booking:detail', kwargs={'pk': self.pk}) return reverse('booking:detail', kwargs={'pk': self.pk})
def __str__(self): def __str__(self):
start = to_current_timezone(self.begin_time)
return 'Buchung von {} am {} von {}-{} Uhr'.format( return 'Buchung von {} am {} von {}-{} Uhr'.format(
self.user, self.user,
self.begin_time.strftime('%d.%m.%Y'), start.strftime('%d.%m.%Y'),
self.begin_time.strftime('%H:%M'), start.strftime('%H:%M'),
self.end_time.strftime('%H:%M') if self.end_time else '') to_current_timezone(self.end_time).strftime('%H:%M')
if self.end_time else '')
@property @property
def duration(self) -> 'int|None': def duration(self) -> 'int|None':