From dd6ef3522337f3ea2f9d4c24d76e57d0546affa4 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 12 Feb 2024 16:26:19 -0500 Subject: [PATCH] membershipworks: Constrain `EventMeetingTime.end` after `start` --- .../0015_eventmeetingtime_end_after_start.py | 18 ++++++++++++++++++ membershipworks/models.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 membershipworks/migrations/0015_eventmeetingtime_end_after_start.py diff --git a/membershipworks/migrations/0015_eventmeetingtime_end_after_start.py b/membershipworks/migrations/0015_eventmeetingtime_end_after_start.py new file mode 100644 index 0000000..bb1da94 --- /dev/null +++ b/membershipworks/migrations/0015_eventmeetingtime_end_after_start.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-02-12 21:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("membershipworks", "0014_remove_eventext_details_timestamp"), + ] + + operations = [ + migrations.AddConstraint( + model_name="eventmeetingtime", + constraint=models.CheckConstraint( + check=models.Q(("end__gt", models.F("start"))), name="end_after_start" + ), + ), + ] diff --git a/membershipworks/models.py b/membershipworks/models.py index 5df7c6b..56835d2 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -565,7 +565,8 @@ class EventMeetingTime(models.Model): constraints = [ models.UniqueConstraint( fields=["event", "start", "end"], name="unique_event_start_end" - ) + ), + models.CheckConstraint(check=Q(end__gt=F("start")), name="end_after_start"), ]