aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/register/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-11 16:13:00 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-11 16:13:00 +0100
commit777372e75bc46fa60e68afcf185642ed38d57e5c (patch)
tree510aff77596a172ee4d28449c6ee15730142bc4e /ctrack/register/models.py
parentf69d29b53b6273d1b1d72cbcce4195e42788d556 (diff)
fixed constraint for CAF event
Diffstat (limited to '')
-rw-r--r--ctrack/register/models.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index 06c0959..0358b00 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -5,6 +5,7 @@ from typing import Optional, Dict
from django.contrib.auth import get_user_model
from django.db import models
+from django.db.models import Q
from ctrack.caf.models import CAF
from ctrack.organisations.models import Person
@@ -16,7 +17,6 @@ class EventType(Enum):
PHONE_CALL = auto()
VIDEO_CALL = auto()
CAF_INITIAL_CAF_RECEIVED = auto()
- CAF_INITIAL_CAF_EMAILED_ROSA = auto()
CAF_FEEDBACK_EMAILED_OES = auto()
CAF_RECEIVED = auto()
CAF_EMAILED_ROSA = auto()
@@ -132,9 +132,13 @@ class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin):
class Meta:
constraints = [
+ # We can't do multiple CAFSingleDateEvents in a single day unless
+ # the type is declared with the Q expression.
models.UniqueConstraint(
- fields=["date", "type_descriptor"], name="unique_caf_for_date"
- )
+ fields=["date", "type_descriptor"],
+ condition=~Q(type_descriptor="CAF_EMAILED_ROSA"),
+ name="unique_caf_for_date",
+ ),
]