[docs]classDayType(models.Model):name=models.CharField(max_length=100)codenames=models.ManyToManyField("CodeName",blank=True)special=models.BooleanField(default=False)blocks=models.ManyToManyField("Block",blank=True)def__str__(self):returnself.name@propertydefclass_name(self):n=self.name.lower()t="other"if"blue day"innor"mod blue"inn:t="blue"if"red day"innor"mod red"inn:t="red"if"anchor day"innor"mod anchor"inn:t="anchor"ifself.special:returnf"day-type-{t} day-special"else:returnf"day-type-{t}"@propertydefstart_time(self)->Time:"""Returns Time the school day begins. Returns None if there are no blocks. Returns: The Time at which the school day starts, or None if there are no blocks. """first_block=self.blocks.first()returnfirst_block.startiffirst_blockisnotNoneelseNone@propertydefend_time(self)->Time:"""Returns Time the school day ends. Returns None if there are no blocks. Returns: The Time at which the school day ends, or None if there are no blocks. """last_block=self.blocks.last()returnlast_block.endiflast_blockisnotNoneelseNone@propertydefno_school(self)->bool:"""Returns True if no blocks are scheduled. Returns: Whether there are no blocks scheduled. """returnnotself.blocks.exists()classMeta:ordering=("name",)
[docs]defget_future_days(self):"""Return only future Day objects."""today=timezone.now().date()returnDay.objects.filter(date__gte=today)
[docs]deftoday(self):"""Return the Day for the current day"""today=timezone.localdate()try:returnDay.objects.get(date=today)exceptDay.DoesNotExist:returnNone
[docs]classDay(models.Model):objects=DayManager()date=models.DateField(unique=True)day_type=models.ForeignKey("DayType",on_delete=models.CASCADE)comment=models.CharField(max_length=1000,blank=True)@propertydefstart_time(self):"""Return time the school day begins"""returnself.day_type.start_time@propertydefend_time(self):"""Return time the school day ends"""returnself.day_type.end_timedef__str__(self):returnf"{self.date}: {self.day_type}"classMeta:ordering=("date",)