diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 14:50:16 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 14:50:16 +0100 |
commit | 0bd4f8e84e4d1788d6119a78823881a96c039427 (patch) | |
tree | 9cda64f75df57406c88ab79f4d5306862af8c901 /ctrack/register/models.py | |
parent | 3f818f99669ab0b49f98b7e7da43c38dc119bfd5 (diff) |
more constraints added at form and model level
Diffstat (limited to '')
-rw-r--r-- | ctrack/register/models.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 9e0516e..03a7d80 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -5,7 +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 django.db.models import Q, F from ctrack.caf.models import CAF from ctrack.organisations.models import Person @@ -170,10 +170,22 @@ class CAFTwinDateEvent(EventBase, CAFMixin, TwinDateMixin): blank=False, max_length=50, choices=AVAILABLE_TYPES ) + def __repr__(self): + return "".join(["CAFTwinDateEvent(", self.type_descriptor, ")"]) -# OLD CODE BELOW + def __str__(self): + return f"CAFTwinDateEvent({self.type_descriptor}) starting {self.start_date}" + + class Meta: + constraints = [ + models.CheckConstraint( + name="end_date_cannot_precede_start_date", + check=~Q(end_date__lt=F("start_date")), + ) + ] +# OLD CODE BELOW class EngagementType(models.Model): """ Examples here are Phone, Email, Letter, Site visit, Meeting, Audit, Inspection, etc. |