diff options
-rw-r--r-- | program/models.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/program/models.py b/program/models.py index 3d71911..c176fda 100644 --- a/program/models.py +++ b/program/models.py @@ -373,10 +373,13 @@ class ProgramSlot(models.Model): timeslot_count.description = _("Time slot count") def has_active_timeslot(self): - start = self.timeslots.all().order_by("start")[0].start - end = self.timeslots.all().order_by("-end")[0].end - now = datetime.now() - return (start < now and end > now) + if self.timeslots.count() > 0: + start = self.timeslots.all().order_by("start")[0].start + end = self.timeslots.all().order_by("-end")[0].end + now = datetime.now() + return (start < now and end > now) + else: + return False class TimeSlotManager(models.Manager): def get_or_create_current(self): |