Skip to content
Snippets Groups Projects
Verified Commit add5e024 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Improve models by fixing labels and adding check constraints

parent cd2f1a17
No related branches found
No related tags found
1 merge request!2Resolve "Frontend for Models"
# Generated by Django 4.2.4 on 2023-09-16 18:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("lesrooster", "0011_alter_lesroosterglobalpermissions_options"),
]
operations = [
migrations.AlterField(
model_name="timeboundcourseconfig",
name="lesson_quota",
field=models.PositiveSmallIntegerField(
blank=True,
help_text="Number of slots this course is scheduled to fill per week",
null=True,
verbose_name="Lesson quota",
),
),
migrations.AddConstraint(
model_name="slot",
constraint=models.CheckConstraint(
check=models.Q(("time_start__lte", models.F("time_end"))),
name="time_start_lte_time_end",
),
),
migrations.AddConstraint(
model_name="validityrange",
constraint=models.CheckConstraint(
check=models.Q(("date_start__lte", models.F("date_end"))),
name="date_start_lte_date_end",
),
),
]
......@@ -4,7 +4,7 @@ from typing import Optional, Union
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q, QuerySet
from django.db.models import F, Q, QuerySet
from django.utils import timezone
from django.utils.formats import date_format, time_format
from django.utils.functional import classproperty
......@@ -111,6 +111,9 @@ class ValidityRange(ExtensibleModel):
condition=Q(status=ValidityRangeStatus.PUBLISHED),
name="lr_unique_dates_per_term",
),
models.CheckConstraint(
check=Q(date_start__lte=F("date_end")), name="date_start_lte_date_end"
),
]
indexes = [
models.Index(fields=["date_start", "date_end"], name="lr_validity_date_start_end")
......@@ -212,6 +215,9 @@ class Slot(ExtensiblePolymorphicModel):
models.UniqueConstraint(
fields=["weekday", "period", "time_grid"], name="lr_unique_period_per_range"
),
models.CheckConstraint(
check=Q(time_start__lte=F("time_end")), name="time_start_lte_time_end"
),
]
ordering = ["weekday", "period"]
indexes = [models.Index(fields=["time_start", "time_end"])]
......@@ -668,7 +674,8 @@ class TimeboundCourseConfig(ExtensibleModel):
)
lesson_quota = models.PositiveSmallIntegerField(
verbose_name=_("Number of slots this course is scheduled to fill per week"),
verbose_name=_("Lesson quota"),
help_text=_("Number of slots this course is scheduled to fill per week"),
blank=True,
null=True,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment