aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-05-31 16:32:49 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-05-31 16:32:49 +0100
commit656ceb510d535d0592cda7cc92bbe0e43561ea0c (patch)
tree4040be410d5c8b758ad96cf6aefe0dd2586d9aa6 /ctrack/organisations/models.py
parent5c8c748c50ac4f6603fccf03c5e8473c47638cf6 (diff)
added sentinel user
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/models.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index 75b28df..4a0b17c 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -184,6 +184,14 @@ class Stakeholder(models.Model):
class IncidentReport(models.Model):
+ def get_sentinel_user(): # type: ignore
+ """
+ We need this so that we can ensure models.SET() is applied with a callable
+ to handle when Users are deleted from the system, preventing the Person objects
+ related to them being deleted also.
+ """
+ return get_user_model().objects.get_or_create(username="DELETED USER")[0]
+
DFT_HANDLE_STATUS = (
("QUEUED", "QUEUED"),
("REVIEWING", "REVIEWING"),
@@ -212,7 +220,7 @@ class IncidentReport(models.Model):
reporting_person = models.ForeignKey(
Person,
blank=False,
- on_delete=models.CASCADE,
+ on_delete=models.SET(get_user_model),
verbose_name="Person " "reporting the incident",
)
person_involved = models.CharField(