diff --git a/aleksis/apps/lesrooster/admin.py b/aleksis/apps/lesrooster/admin.py index 7277556372c304a5512a0fae39b85a52fad113c7..c04107549275dce4f357c068466b8ad38f3189e3 100644 --- a/aleksis/apps/lesrooster/admin.py +++ b/aleksis/apps/lesrooster/admin.py @@ -17,7 +17,7 @@ admin.site.register(ValidityRange, ValidityRangeAdmin) class SlotAdmin(admin.ModelAdmin): - list_display = ("school_term", "weekday", "period", "time_start", "time_end") + list_display = ("validity_range", "weekday", "period", "time_start", "time_end") list_display_links = ("weekday", "period") diff --git a/aleksis/apps/lesrooster/models.py b/aleksis/apps/lesrooster/models.py index 2fcfc4e488610dbc5b8f184a47e93636e5a441af..dd6800cad5176070d0bf5ccde187587f6b917f51 100644 --- a/aleksis/apps/lesrooster/models.py +++ b/aleksis/apps/lesrooster/models.py @@ -90,7 +90,7 @@ class Slot(ExtensiblePolymorphicModel): WEEKDAY_CHOICES_SHORT = i18n_day_abbr_choices_lazy() validity_range = models.ForeignKey( - "chronos.ValidityRange", + "lesrooster.ValidityRange", on_delete=models.CASCADE, related_name="slots", verbose_name=_("Linked validity range"), @@ -133,11 +133,16 @@ class Slot(ExtensiblePolymorphicModel): day = self.get_date(date_ref) return datetime.combine(day, self.time_end) + @property + def lessons(self): + # FIXME: this may not be the intended behaviour of this property + return Lesson.objects.filter(models.Q(lesson_start=self) | models.Q(lesson_end=self)) + class Meta: constraints = [ # Heads up: Uniqueness per validity range implies validity per site models.UniqueConstraint( - fields=["weekday", "period", "validity"], name="unique_period_per_range" + fields=["weekday", "period", "validity_range"], name="unique_period_per_range" ), ] ordering = ["weekday", "period"] @@ -161,13 +166,13 @@ class Lesson(ExtensibleModel): Slot, on_delete=models.CASCADE, verbose_name=_("Start slot"), - related_name="lessons", + related_name="lessons_starting", ) slot_end = models.ForeignKey( Slot, on_delete=models.CASCADE, verbose_name=_("End slot"), - related_name="lessons", + related_name="lessons_ending", ) # Recurrence rules allow to define a series of lessons @@ -212,7 +217,7 @@ class Lesson(ExtensibleModel): class Meta: # Heads up: Link to slot implies uniqueness per site ordering = [ - "slot_start__validity__date_start", + "slot_start__validity_range__date_start", "slot_start__weekday", "slot_start__time_start", "subject",