add duration to eventsession constraints

This commit is contained in:
Thomas Steen Rasmussen 2020-06-22 10:54:09 +02:00
parent 9fce167c7c
commit daefd62f96
2 changed files with 22 additions and 3 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 3.0.3 on 2020-06-22 00:06
# Generated by Django 3.0.3 on 2020-06-22 08:51
import django.contrib.postgres.constraints
from django.db import migrations, models
@ -11,6 +11,10 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RemoveConstraint(
model_name="eventsession",
name="prevent_event_session_event_type_event_location_overlaps",
),
migrations.AlterField(
model_name="event",
name="duration_minutes",
@ -32,8 +36,21 @@ class Migration(migrations.Migration):
model_name="eventsession",
constraint=django.contrib.postgres.constraints.ExclusionConstraint(
expressions=[
("when", "&&"),
("event_location", "="),
("event_type", "="),
("event_duration_minutes", "="),
],
name="prevent_event_session_event_type_event_location_overlaps",
),
),
migrations.AddConstraint(
model_name="eventsession",
constraint=django.contrib.postgres.constraints.ExclusionConstraint(
expressions=[
("event_location", "="),
("event_type", "="),
("event_duration_minutes", "="),
("when", "-|-"),
],
name="prevent_adjacent_eventsessions",

View file

@ -833,21 +833,23 @@ class EventSession(CampRelatedModel):
class Meta:
ordering = ["when", "event_type", "event_location"]
constraints = [
# We do not want overlapping sessions for the same EventType/EventLocation combo.
# We do not want overlapping sessions for the same EventType/EventLocation/duration combo.
ExclusionConstraint(
name="prevent_event_session_event_type_event_location_overlaps",
expressions=[
("when", RangeOperators.OVERLAPS),
("event_location", RangeOperators.EQUAL),
("event_type", RangeOperators.EQUAL),
("event_duration_minutes", RangeOperators.EQUAL),
],
),
# we do not want adjacent sessions for the same type and location
# we do not want adjacent sessions for the same type and location and duration
ExclusionConstraint(
name="prevent_adjacent_eventsessions",
expressions=[
("event_location", RangeOperators.EQUAL),
("event_type", RangeOperators.EQUAL),
("event_duration_minutes", RangeOperators.EQUAL),
("when", RangeOperators.ADJACENT_TO),
],
),