aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/caf
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-08-26 13:40:13 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-08-26 13:40:13 +0100
commit6f4ea7ef9018e2e1df396f16aa4080dcee3ef6df (patch)
tree519d1e9c079879d3fc2cd8beec65d6ddb1c30804 /ctrack/caf
parent15c89a78c097dc00ad7b8ca3314581ed3b058187 (diff)
started the rebuild
Diffstat (limited to 'ctrack/caf')
-rw-r--r--ctrack/caf/managers.py12
-rw-r--r--ctrack/caf/models.py7
2 files changed, 14 insertions, 5 deletions
diff --git a/ctrack/caf/managers.py b/ctrack/caf/managers.py
index cba8c83..4d8c134 100644
--- a/ctrack/caf/managers.py
+++ b/ctrack/caf/managers.py
@@ -1,8 +1,8 @@
from django.db import connection
from django.db import models
-import ctrack.caf.models # to deal with circular import
-from ctrack.organisations.models import Organisation, Person
+import ctrack.caf.models as caf_models # to deal with circular import
+import ctrack.organisations.models as org_models
class ApplicableSystemManager(models.Manager):
@@ -16,14 +16,16 @@ class ApplicableSystemManager(models.Manager):
Using Custom Managers Django docs for an example.
"""
with connection.cursor() as cursor:
- cursor.execute("""
+ cursor.execute(
+ """
SELECT a.id, a.name, o.id, c.id, sm.id, p.id, o.name
FROM caf_applicablesystem a, organisations_organisation o, organisations_person p, caf_caf c, organisations_submode sm
WHERE a.organisation_id = o.id AND a.caf_id = c.id AND p.organisation_id = o.id AND o.submode_id = sm.id AND p.primary_nis_contact = True;
- """)
+ """
+ )
result_list = []
for row in cursor.fetchall():
- org = Organisation.objects.get(pk=row[2])
+ org = org_models.Organisation.objects.get(pk=row[3])
caf = ctrack.caf.models.CAF.objects.get(pk=row[3])
ass = self.model(id=row[0], name=row[1], organisation=org, caf=caf)
ass.nis_contact = Person.objects.get(pk=row[5])
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index 27220bc..a4afc29 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -158,3 +158,10 @@ class CAF(models.Model):
# Get the organisation and applicable system
ass = ApplicableSystem.objects.filter(caf=self).first()
return f"CAF | {ass.organisation.name}_v{self.version}"
+
+
+class EssentialService(models.Model):
+ name = models.CharField(max_length=256)
+ description = models.CharField(max_length=512)
+ organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
+ systems = models.ManyToManyField(ApplicableSystem)