From 15a1182feaf78af0662244dffe8d10dd026ded69 Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Wed, 20 Apr 2022 18:57:04 +0200 Subject: [PATCH] black --- shiftregister/app/models.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index c2452b9..4fead8f 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -21,10 +21,12 @@ class Shift(models.Model): # todo: add helper amount override field def __str__(self): return f"{self.room.name}: {self.start_at}" + def has_ended(self): return (self.start_at + self.duration) < timezone.now() + def is_running(self): - return (self.start_at <=timezone.now()) and (not self.has_ended()) + return (self.start_at <= timezone.now()) and (not self.has_ended()) class Helper(models.Model): @@ -43,19 +45,24 @@ class Helper(models.Model): msg = Message(to=self, text=text) msg.save() return token - + # current or next shift def important_shift(self): - ret = ShiftRegistration.objects.annotate( + ret = ( + ShiftRegistration.objects.annotate( shift_end=ExpressionWrapper( F("shift__start_at") + F("shift__duration"), output_field=models.DateTimeField(), - )).filter(helper=self, shift_end__gte=timezone.now()).order_by("shift__start_at").first() + ) + ) + .filter(helper=self, shift_end__gte=timezone.now()) + .order_by("shift__start_at") + .first() + ) if ret: return ret.shift - class ShiftRegistration(models.Model): class Meta: unique_together = (("shift", "helper"),)