add constraint to prevent adjacent eventsessions for the same eventtype and location, and add some missing migrations

This commit is contained in:
Thomas Steen Rasmussen 2020-06-22 02:02:29 +02:00
parent 8efac62f62
commit 7b435ace42
2 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,54 @@
# Generated by Django 3.0.3 on 2020-06-21 23:56
import uuid
import django.contrib.postgres.constraints
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("program", "0094_tags_blank"),
]
operations = [
migrations.AlterField(
model_name="event",
name="duration_minutes",
field=models.PositiveIntegerField(
blank=True,
default=None,
help_text="The duration of this event in minutes. Leave blank to use the default from the event_type.",
),
),
migrations.AlterField(
model_name="event",
name="uuid",
field=models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="This field is not the PK of the model. It is used to create EventSlot UUID for FRAB and iCal and other calendaring purposes.",
unique=True,
),
),
migrations.AlterField(
model_name="eventproposal",
name="duration",
field=models.IntegerField(
blank=True,
help_text="How much time (in minutes) should we set aside for this event?",
),
),
migrations.AddConstraint(
model_name="eventsession",
constraint=django.contrib.postgres.constraints.ExclusionConstraint(
expressions=[
("event_location", "="),
("event_type", "="),
("when", "-|-"),
],
name="prevent_adjacent_eventsessions",
),
),
]

View File

@ -521,7 +521,7 @@ class EventProposal(UserSubmittedModel):
duration = models.IntegerField(
blank=True,
help_text="How much time (in minutes) should we set aside for this act? Please keep it between 60 and 180 minutes (1-3 hours).",
help_text="How much time (in minutes) should we set aside for this event?",
)
submission_notes = models.TextField(
@ -842,6 +842,15 @@ class EventSession(CampRelatedModel):
("event_type", RangeOperators.EQUAL),
],
),
# we do not want adjacent sessions for the same type and location
ExclusionConstraint(
name="prevent_adjacent_eventsessions",
expressions=[
("event_location", RangeOperators.EQUAL),
("event_type", RangeOperators.EQUAL),
("when", RangeOperators.ADJACENT_TO),
],
),
]
camp = models.ForeignKey(